Git Cheatsheet
Quick reference for Git commands covering basics, branching, remote operations, stash, log, rebase, tagging, and configuration
79 commands
git initInitialize a new Git repository
git initgit cloneClone a remote repository
git clone https://github.com/user/repo.gitgit clone --depthCreate a shallow clone
git clone --depth 1 https://github.com/user/repo.gitgit addAdd files to staging area
git add file.txtgit add -AAdd all changes to staging
git add -Agit add -pStage changes interactively
git add -pgit commitCommit staged changes
git commit -m 'Add new feature'git commit --amendAmend last commit
git commit --amend -m 'Updated message'git statusShow working tree status
git statusgit rmRemove file and stage deletion
git rm file.txtgit rm --cachedUntrack file without deleting
git rm --cached secret.envgit mvMove or rename a file
git mv old_name.txt new_name.txtgit branchList local branches
git branchgit branch -aList all branches including remote
git branch -agit branch (create)Create a new branch
git branch feature/logingit branch -dDelete merged branch
git branch -d feature/logingit branch -DForce delete branch
git branch -D feature/experimentalgit branch -mRename a branch
git branch -m old-name new-namegit checkoutSwitch to a branch
git checkout maingit checkout -bCreate and switch to branch
git checkout -b feature/signupgit switchSwitch branch (modern command)
git switch maingit switch -cCreate and switch branch (modern)
git switch -c feature/dashboardgit remote -vList remote repositories
git remote -vgit remote addAdd a remote repository
git remote add origin https://github.com/user/repo.gitgit remote removeRemove a remote repository
git remote remove upstreamgit remote renameRename a remote repository
git remote rename origin upstreamgit fetchFetch changes without merge
git fetch origingit fetch --prunePrune deleted remote branches
git fetch --prunegit pullFetch and merge remote changes
git pull origin maingit pull --rebasePull with rebase
git pull --rebase origin maingit pushPush local changes to remote
git push origin maingit push -uPush and set upstream branch
git push -u origin feature/logingit push --force-with-leaseSafe force push
git push --force-with-leasegit stashStash current changes
git stashgit stash -mStash with message
git stash -m 'WIP: login feature'git stash listList all stashes
git stash listgit stash popApply and remove latest stash
git stash popgit stash applyApply stash without removing
git stash apply stash@{0}git stash dropDrop a stash
git stash drop stash@{0}git stash clearClear all stashes
git stash cleargit stash showShow stash changes
git stash show -p stash@{0}git stash branchCreate branch from stash
git stash branch feature/from-stash stash@{0}git logShow commit history
git loggit log --onelineShow compact commit history
git log --onelinegit log --graphShow log with branch graph
git log --graph --oneline --allgit log -pShow log with diffs
git log -p -2git log --authorShow commits by author
git log --author='John'git log --sinceShow commits since date
git log --since='2024-01-01'git diffShow unstaged changes
git diffgit diff --stagedShow staged changes
git diff --stagedgit diff branch1..branch2Show diff between branches
git diff main..feature/logingit blameShow who changed each line
git blame file.txtgit shortlogShow commit summary by author
git shortlog -sngit mergeMerge a branch
git merge feature/logingit merge --no-ffMerge without fast-forward
git merge --no-ff feature/logingit merge --squashSquash merge
git merge --squash feature/logingit rebaseRebase current branch
git rebase maingit rebase --abortAbort rebase
git rebase --abortgit rebase --continueContinue rebase after conflict
git rebase --continuegit cherry-pickApply specific commit
git cherry-pick abc1234git revertCreate commit that reverts changes
git revert abc1234git reset --softUndo commit keeping changes staged
git reset --soft HEAD~1git reset --mixedUndo commit keeping changes unstaged
git reset HEAD~1git tagList all tags
git taggit tag (lightweight)Create lightweight tag
git tag v1.0.0git tag -aCreate annotated tag
git tag -a v1.0.0 -m 'Release v1.0.0'git tag -dDelete local tag
git tag -d v1.0.0git push origin --tagsPush all tags to remote
git push origin --tagsgit push origin --delete tagDelete remote tag
git push origin --delete v1.0.0git show tagShow tag details
git show v1.0.0git config --global user.nameSet global user name
git config --global user.name 'John Doe'git config --global user.emailSet global email
git config --global user.email 'john@example.com'git config --listList all config settings
git config --listgit config --global core.editorSet default editor
git config --global core.editor 'vim'git clean -fdRemove untracked files
git clean -fdgit clean -nDry run to see files to clean
git clean -ngit bisect startStart binary search for bug
git bisect startgit reflogShow reference log
git refloggit worktree addAdd a working tree
git worktree add ../feature-branch feature/login