처음 시작할 때 초기 설정 (Initial setup at first start)
1. GitHub에 저장소 만들기 (Create Repository on GitHub)
- GitHub 사이트에서 'New repository' 클릭 (Click 'New repository' on the GitHub site)
- 저장소 이름 입력 후 생성 (Create after entering a repository name)
2. 로컬에서 Git 초기화 및 연결 (Initialize and connect to Git locally)
bash
git init
git remote add origin https://github.com/아이디(id)/저장소이름(repository).git
git branch -M main
📤 파일 업로드하기 (Uploading a File)
기본 명령어 (basic command)
bash
git pull origin main # 최신 상태 동기화(Synchronize the latest status)
git add . # 모든 변경사항 추가(Add all changes)
git commit -m "메시지(Message)" # 변경사항 확정(Confirmation of changes)
git push origin main # GitHub에 업로드(Upload to GitHub)
origin은 변수 역할을 담당 사용자가 마음대로 변경 가능.
💡 자주 쓰는 명령어 (a frequently used command)
명령어설명
| git status | 변경된 파일 확인 (Check the changed file ) |
| git remote -v | 연결된 원격 저장소 확인 (Verifying Connected Remote Repositoty) |
| git branch | 현재 브랜치 확인 (Check current branch) |
| git pull | 원격 저장소에서 파일 가져오기 (Import files from remote repository) |
⚡ 간편 설정 [한 번만 하면 됨] (Easy Settings [Just One Time])
bash
# 기본 브랜치 이름을 main으로 설정 (Set the default branch name to main)
git config --global init.defaultBranch main
# push할 때 브랜치 이름 생략 가능하게 설정 (Set the branch name to be omitted when pushing)
git push -u origin main
# 이후부터는 git push만 입력해도 됨 (From now on, you can only enter git push)
📝 실제 작업 흐름
- 처음(First time): 저장소 생성(Create Repository) → 연결(Connection) → 파일(File) push
- 이후(After this): pull → 작업(Work) → add → commit → push 반복(Repetition)
추가
git remote 삭제 방법
git remote remove <remote 이름>
git log 한눈에 보는 방법
git log --all --decorate --oneline --graph