기본 명령어
git config --list
: git 설정 확인
git --version
: git 버전 확인
git update-git-for-windows
: git 업그레이드(윈도우 사용자)
git init
: git 생성하기
git status
: 현재 상태 보기
git log
: 모든 commit 내용 보기
git log --oneline
: 모든 commit 내용을 간단하게 보기
git log --all
: 모든 branch의 commit 내용 보기
git log --graph
: 모든 commit 내용을 graph로 보기
git reflog
: HEAD가 움직인 이력 보기
git config --global user.name "user_name"
: git 계정 Name 변경하기
git config --global user.email "user_email"
: git 계정 Mail 변경하기
Commit 관련 명령어
git add "file_path"
: 해당 파일 Stage Area에 추가하기 ( git add * or git add .)
git restore --staged "file_path"
: 해당 파일을 unstage
git restore "file_path"
: (unstage 상태의) 변경된 내용 되돌리기
git commit -m "commit_description"
: 해당 내용으로 commit 만들기 ( git commit -m “내용”)
git commit --amend
: 현재 commit에 덮어쓰기
git commit --amend -m "commit_description"
: 현재 commit에 덮어쓰면서 commit 내용을 변경
git rm "file_path"
: 해당 파일 삭제 후 Stage Area에 추가하기 (= 파일 삭제 + add "file_path" )
git reset "commit_ID"
: 코드는 (unstaged 상태로) 살리고 해당 commit으로 돌아가면서 그 이후 commit 삭제
git reset HEAD^
: 코드는 (unstaged 상태로) 살리고 바로 이전 commit으로 돌아가기
git reset --soft "commit_ID"
: 코드는 (staged 상태로) 살리고 해당 commit으로 돌아가면서 그 이후 commit 삭제
git reset --soft HEAD^
: 코드는 (staged 상태로) 살리고 바로 이전 commit으로 돌아가기
git reset --hard "commit_ID"
: 해당 commit으로 돌아가면서 그 이후 commit은 삭제
git reset --hard HEAD^
: 바로 이전 commit으로 돌아가기(HEAD^, HEAD@{1}, HEAD~1 사용 가능)
git revert "commit_ID" --no-edit
: 새로운 commit을 만들면서 이전 commit으로 돌아가기
git revert --continue --no-edit
: revert 하면서 충돌난 부분을 해결한 다음 계속 진행하기
git checkout "commit_ID"
: HEAD를 해당 commit으로 옮기기
Branch 관련 명령어
git branch "branch_name"
: 브랜치 생성하기
git branch
: 로컬 브랜치 목록보기
git branch -r
: 원격 브랜치 목록보기
git branch -a
: 모든 브랜치 목록보기
git branch -m "branch_name" "new_branch_name"
: 브랜치 이름 바꾸기
git branch -d "branch_name"
: 브랜치 삭제하기
git switch(예전에는 checkout) "branch_name"
: 브랜치 선택하기
git switch(예전에는 checkout) -t "remote_name"/"branch_name"
: 원격 브랜치를 로컬 브랜치로 만들고 선택하기
git merge "branch_name"
: 현재 브랜치에 해당 브랜치를 머지하기
git merge --squash "branch_name"
: 현재 브랜치에 해당 브랜치의 commit 내용을 하나로 합쳐서 머지하기(commit 필요)
git rebase "branch_name"
: 현재 브랜치를 해당 브랜치에 이어 붙이기
git merge/rebase --continue
: merge 혹은 rebase 중 충돌이 생겼을 때, 충돌 해결 후 계속하기
git merge/rebase --abort
: merge 혹은 rebase 중 충돌이 생겼을 때, merge 혹은 rebase 취소하기
git stash / git stash save "description"
: 작업 코드 임시 저장하기
git stash pop
: 마지막으로 임시 저장한 작업 코드 가져오기
Remote Repository 관련 명령어
git remote add "remote_name" "remote_path"
: 로컬 repository에 원격 repository를 연결
git pull "remote_name" "branch_name"
: 연결된 해당 원격 branch의 commit 내용을 현재 로컬 branch에 가져오기
(--set-upstream 또는 -u로 등록하면 다음엔 git pull로 사용 가능)
git branch --set-upstream-to "remote_path"/"branch_name"
: pull, push의 대상을 "remote_path"/"branch_name"으로 설정
git clone "git_path"
: 원격 repository를 로컬 repository로 복사하기(자동 연결)
git push "remote_name" "branch_name"
: 현재 로컬 commit 내용을 원격 branch에 보내기
git push "remote_name" --delete(-d) "branch_name"
: 원격 브랜치 삭제하기
git fetch
: 원격 repository의 변경된 사항을 로컬 repository 원격 branch에 적용(로컬 branch에는 적용X, pull과의 차이)
git fetch -p
: 원격 repository의 삭제된 branch를 로컬 repository 원격 branch에 적용(가지치기)