Git 명령어 치트시트

Git은 파일 변경을 저장소 안 일련의 커밋으로 기록합니다. 이 명령어들은 저장소 만들기, 작업 저장, 브랜치, 머지, 원격 공유 같은 매일의 흐름을 다룹니다. 배우는 동안 곁에 두세요.

업데이트:

명령어하는 일
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

참고

자주 묻는 질문

merge와 rebase의 차이는?
merge는 두 부모를 가진 새 커밋으로 히스토리를 합칩니다. rebase는 커밋을 다른 브랜치 위로 다시 올려 선형 히스토리를 만들지만 커밋 ID를 다시 씁니다.
커밋을 되돌리려면?
'git revert <커밋>'은 변경을 취소하는 새 커밋을 추가합니다(안전, 공유 히스토리 유지). 'git reset'은 히스토리를 다시 쓰므로 공유 브랜치에선 쓰지 마세요.
git pull과 git fetch의 차이는?
fetch는 원격에서 커밋과 참조를 내려받되 작업 트리는 건드리지 않습니다. pull은 fetch한 뒤 그 변경을 현재 브랜치에 merge하거나 rebase합니다.
git stash는 언제 쓰나요?
stash는 커밋하지 않은 변경을 임시 보관해 브랜치 전환이나 깔끔한 pull을 가능하게 하고, 나중에 'git stash pop'으로 복원합니다.