Git Commands Cheat Sheet

Everyday Git commands and what they do. Download: CSV · JSON. Commands marked destructive can lose uncommitted work.

CommandWhat it does
git initCreate a new repository in the current folder
git clone <url>Copy a remote repository locally
git statusShow changed and staged files
git add <file>Stage a file for commit
git add -pStage changes interactively, hunk by hunk
git commit -m "msg"Commit staged changes with a message
git commit --amendRewrite the most recent commit
git log --oneline --graphCompact commit history with branch graph
git diffShow unstaged changes
git diff --stagedShow staged changes
git branch <name>Create a branch
git switch <name>Switch to a branch
git switch -c <name>Create and switch to a new branch
git merge <branch>Merge a branch into the current one
git rebase <branch>Replay current commits on top of another branch
git stashShelve uncommitted changes
git stash popReapply the latest stash
git restore <file>Discard unstaged changes to a file
git restore --staged <file>Unstage a file
git reset --hard HEADDiscard all local changes (destructive)
git revert <commit>Create a commit that undoes another commit
git fetchDownload remote changes without merging
git pull --rebaseFetch and rebase local commits on the remote
git push -u origin <branch>Push a branch and set its upstream
git tag v1.0.0Tag the current commit
git cherry-pick <commit>Apply one commit onto the current branch
git reflogShow history of HEAD movements (recover lost commits)
git blame <file>Show who last changed each line
git bisect startBinary-search for the commit that introduced a bug
git clean -fdRemove untracked files and folders (destructive)