Git 명령어 정리


1. Git 설정

명령어 설명 예시
git config Git 설정 (이름, 이메일, 에디터 등) git config --global user.name "Your Name", git config --global user.email "[email protected]"
git config --list 설정된 Git 정보 확인 git config --list
git config --global core.editor 기본 텍스트 에디터 설정 git config --global core.editor "vim"

2. 저장소 초기화 및 복제

명령어 설명 예시
git init 새로운 Git 저장소 초기화 git init
git clone 원격 저장소 복제 git clone https://github.com/user/repo.git

3. 파일 상태 확인 및 관리

명령어 설명 예시
git status 작업 디렉토리 상태 확인 git status
git add 스테이징 영역에 파일 추가 git add file.txt, git add . (현재 디렉토리 전체 추가)
git rm 파일 삭제 및 Git에서 제거 git rm file.txt
git mv 파일 또는 디렉토리 이름 변경 git mv old_name.txt new_name.txt

4. 커밋 관련 명령어

명령어 설명 예시
git commit 변경 사항을 저장소에 커밋 git commit -m "Add new feature"
git commit --amend 마지막 커밋 메시지 수정 git commit --amend -m "Update commit message"
git log 커밋 이력 확인 git log, git log --oneline (간략한 출력)

5. 브랜치 관리

명령어 설명 예시
git branch 브랜치 목록 확인 및 생성 git branch, git branch new-branch
git checkout 브랜치 변경 또는 특정 커밋 체크아웃 git checkout new-branch, git checkout -b feature-branch (새 브랜치 생성 후 이동)
git switch 브랜치 변경 (checkout 대안) git switch main, git switch -c new-branch
git branch -d 브랜치 삭제 git branch -d old-branch

6. 병합 및 충돌 해결

명령어 설명 예시
git merge 다른 브랜치와 병합 git merge feature-branch
git mergetool 충돌 해결 도구 실행 git mergetool
git diff 변경 사항 확인 git diff, git diff main feature-branch