Git Cheat Sheet
A searchable reference of the Git commands you reach for every day, grouped by category. Find a command, read what it does, and copy it with one click.
69
Commands
10
Categories
69
Showing
Setup & config
7git initCreate an empty Git repository in the current directory.
Examplegit init my-projectgit clone <url>Copy a remote repository, including its full history, locally.
Examplegit clone [email protected]:user/repo.gitgit config --global user.name <name>Set the author name attached to every commit you make.
Examplegit config --global user.name "Ada Lovelace"git config --global user.email <email>Set the author email attached to every commit you make.
Examplegit config --global user.email "[email protected]"git config --global init.defaultBranch <name>Choose the default branch name used by future `git init` calls.
Examplegit config --global init.defaultBranch maingit config --listPrint every effective configuration value and where it came from.
Examplegit config --list --show-origingit config --global alias.<short> <command>Define a shorthand for a longer command you type often.
Examplegit config --global alias.co "checkout"
Staging
7git add <path>Stage changes from a file or directory for the next commit.
Examplegit add src/index.tsgit add .Stage every change in the current directory and below.
git add -pInteractively choose which hunks of each change to stage.
git rm <path>Remove a tracked file from the tree and stage the deletion.
Examplegit rm old-file.txtgit rm --cached <path>Stop tracking a file but keep it on disk (e.g. once gitignored).
Examplegit rm --cached .envgit mv <src> <dest>Rename or move a tracked file and stage the change in one step.
Examplegit mv util.ts helpers.tsgit restore --staged <path>Unstage a file, leaving its working-tree changes untouched.
Examplegit restore --staged src/index.ts
Commit
5git commit -m <message>Record the staged snapshot with a one-line commit message.
Examplegit commit -m "Fix off-by-one in pager"git commit -am <message>Stage every tracked modification and commit it in one step.
Examplegit commit -am "Tidy up imports"git commit --amendRewrite the most recent commit (its message or contents).
Examplegit commit --amend -m "Better message"git commit --amend --no-editFold newly staged changes into the last commit, keeping its message.
git commit --allow-empty -m <message>Record a commit with no changes, e.g. to trigger CI.
Examplegit commit --allow-empty -m "Trigger deploy"
Branches
8git branchList the local branches; the current one is marked with `*`.
Examplegit branch -agit branch <name>Create a new branch at the current commit without switching to it.
Examplegit branch feature/logingit switch <name>Move to an existing branch, updating the working tree.
Examplegit switch maingit switch -c <name>Create a new branch and switch to it in one step.
Examplegit switch -c feature/logingit checkout <name>Switch branches (the classic command; `switch` is the modern split).
Examplegit checkout developgit branch -d <name>Delete a branch that has already been merged.
Examplegit branch -d feature/logingit branch -D <name>Force-delete a branch even if it has unmerged commits.
Examplegit branch -D experimentgit branch -m <old> <new>Rename a branch (omit `<old>` to rename the current branch).
Examplegit branch -m master main
Merge & rebase
8git merge <branch>Join another branch's history into the current branch.
Examplegit merge feature/logingit merge --no-ff <branch>Always create a merge commit, even for a fast-forwardable merge.
Examplegit merge --no-ff release/1.2git merge --abortBail out of an in-progress merge and restore the pre-merge state.
git rebase <branch>Replay the current branch's commits on top of another branch.
Examplegit rebase maingit rebase -i <ref>Interactively reorder, squash, edit, or drop a range of commits.
Examplegit rebase -i HEAD~3git rebase --continueResume a rebase after resolving the current conflict.
git rebase --abortCancel an in-progress rebase and return to the original state.
git cherry-pick <commit>Apply the change introduced by one commit onto the current branch.
Examplegit cherry-pick a1b2c3d
Remotes
8git remote -vList the configured remotes and their fetch/push URLs.
git remote add <name> <url>Register a new remote repository under a short name.
Examplegit remote add origin [email protected]:user/repo.gitgit fetch <remote>Download new objects and refs from a remote without merging.
Examplegit fetch origingit pullFetch from the tracked remote branch and integrate it into yours.
Examplegit pull --rebasegit pushUpload local commits on the current branch to its remote.
Examplegit push origin maingit push -u <remote> <branch>Push a branch and set it to track the remote for future pulls.
Examplegit push -u origin feature/logingit push --force-with-leaseForce-push safely, refusing to clobber remote work you have not seen.
git push <remote> --delete <branch>Delete a branch on the remote.
Examplegit push origin --delete feature/login
Undoing things
7git restore <path>Discard working-tree changes in a file, reverting to HEAD.
Examplegit restore src/index.tsgit restore --source <ref> <path>Restore a file's contents from a specific commit.
Examplegit restore --source HEAD~2 README.mdgit reset <path>Unstage a file while keeping the working-tree changes.
Examplegit reset src/index.tsgit reset --soft <ref>Move HEAD to a commit but keep changes staged.
Examplegit reset --soft HEAD~1git reset --hard <ref>Move HEAD and discard all staged and working-tree changes.
Examplegit reset --hard origin/maingit revert <commit>Create a new commit that undoes a previous one, keeping history.
Examplegit revert a1b2c3dgit clean -fdDelete untracked files and directories from the working tree.
Examplegit clean -fdn
Stash
6git stashShelve uncommitted changes and revert to a clean working tree.
Examplegit stash push -m "WIP login form"git stash -uStash changes including untracked files.
git stash listShow all stashed change sets you have saved.
git stash popReapply the most recent stash and remove it from the list.
git stash apply <stash>Reapply a stash but keep it in the list for reuse.
Examplegit stash apply stash@{1}git stash drop <stash>Delete a single stash from the list.
Examplegit stash drop stash@{0}
Inspecting history
7git statusShow staged, unstaged, and untracked changes in the working tree.
Examplegit status -sgit logShow the commit history of the current branch.
Examplegit log --oneline --graph --allgit diffShow unstaged changes between the working tree and the index.
Examplegit diff --stagedgit show <ref>Show the metadata and diff introduced by one commit.
Examplegit show HEADgit blame <path>Annotate each line of a file with the commit that last changed it.
Examplegit blame src/index.tsgit reflogList every position HEAD has pointed to — a safety net for recovery.
git bisect startBegin a binary search through history to find a regression.
Examplegit bisect bad && git bisect good v1.0
Tags & releases
6git tagList the existing tags in the repository.
Examplegit tag -l "v1.*"git tag <name>Create a lightweight tag pointing at the current commit.
Examplegit tag v1.2.0git tag -a <name> -m <message>Create an annotated tag with its own message and metadata.
Examplegit tag -a v1.2.0 -m "Release 1.2.0"git push <remote> <tag>Publish a single tag to a remote.
Examplegit push origin v1.2.0git push <remote> --tagsPublish every local tag to a remote at once.
Examplegit push origin --tagsgit tag -d <name>Delete a local tag.
Examplegit tag -d v1.2.0
About this sheet
Commands are drawn from the official Git reference manual and the Pro Git book. Angle brackets (like <branch>) are placeholders to swap for your own value. Nothing leaves your browser — this page is entirely client-side.