Git cheat sheet — 62 everyday commands you can search by task

Type what you want to do, such as undo or stash, or pick a topic, and the cheat sheet lists the matching Git commands with a one-line explanation of each, from first-time setup to rebasing, tagging and worktrees.

Live demo · real result from this tool
Showing62 of 62 commands

Table

CommandWhat it doesTopic
git config --global user.name "Name"Set the name recorded in your commits.Setup
git config --global user.email "you@example.com"Set the email recorded in your commits.Setup
git config --global init.defaultBranch mainName the first branch of new repositories main.Setup
git initCreate a new repository in the current folder.Setup
git clone <url>Copy a remote repository, with its full history.Setup
git clone --depth 1 <url>Shallow clone: only the latest commit.Setup
git statusShow changed, staged and untracked files.Basics
git add <file>Stage a file for the next commit.Basics
git add -pStage changes hunk by hunk, interactively.Basics
git commit -m "message"Record the staged changes.Basics
git commit --amendReplace the last commit (message or content). Avoid on pushed commits.Basics
git diffShow unstaged changes.Basics
git diff --stagedShow staged changes.Basics
git restore <file>Discard unstaged changes to a file.Undo
git restore --staged <file>Unstage a file, keeping its changes.Undo
git rm <file>Delete a file and stage the deletion.Basics
git mv <old> <new>Rename a file and stage the rename.Basics
git branchList local branches.Branches
git branch <name>Create a branch.Branches
git switch <name>Switch to a branch.Branches
git switch -c <name>Create a branch and switch to it.Branches
git branch -d <name>Delete a merged branch (-D forces).Branches
git branch -m <new>Rename the current branch.Branches
git merge <branch>Merge a branch into the current one.Branches
git merge --abortGive up a merge with conflicts.Branches
git rebase <branch>Replay your commits on top of another branch.Branches
git rebase -i HEAD~3Edit, squash or reorder the last 3 commits.Branches
git rebase --abortStop a rebase and return to where you started.Branches
git cherry-pick <commit>Apply one commit from elsewhere onto the current branch.Branches
git remote -vList remotes and their URLs.Remotes
git remote add origin <url>Connect a remote.Remotes
git fetchDownload remote changes without merging.Remotes
git pullFetch and merge (or rebase, if configured) the upstream branch.Remotes
git pull --rebaseFetch and rebase your local commits on top.Remotes
git pushUpload commits to the upstream branch.Remotes
git push -u origin <branch>Push a new branch and set its upstream.Remotes
git push --force-with-leaseForce-push, refusing if someone else pushed meanwhile.Remotes
git push origin --delete <branch>Delete a remote branch.Remotes
git log --oneline --graph --allCompact history graph of all branches.History
git log -p <file>History of a file with diffs.History
git show <commit>Show a commit's message and changes.History
git blame <file>Show who last changed each line.History
git log -S "text"Find commits that added or removed text.History
git reflogEvery position HEAD has been at — the way to recover "lost" commits.History
git bisect startBinary-search history for the commit that introduced a bug.History
git reset --soft HEAD~1Undo the last commit, keep its changes staged.Undo
git reset HEAD~1Undo the last commit, keep its changes unstaged.Undo
git reset --hard HEAD~1Undo the last commit and discard its changes (destructive).Undo
git revert <commit>Create a new commit that undoes a commit — safe on shared branches.Undo
git clean -nPreview untracked files that clean would delete (-f to delete).Undo
git stashShelve uncommitted changes.Stash
git stash -uStash including untracked files.Stash
git stash listList stashes.Stash
git stash popRe-apply the latest stash and drop it.Stash
git stash apply stash@{1}Apply a specific stash and keep it.Stash
git tag v1.0.0Create a lightweight tag.Tags
git tag -a v1.0.0 -m "Release"Create an annotated tag.Tags
git push --tagsPush tags to the remote.Tags
git worktree add ../dir <branch>Check out another branch in a second folder.Advanced
git submodule update --init --recursiveFetch submodules.Advanced
git sparse-checkout set <dir>Check out only part of a large repository.Advanced
git gcClean up and compress the repository.Advanced

62 rows — scroll inside the table, or download the CSV.

Processed on your device — nothing is uploaded.

How to use the Git cheat sheet

  1. Type a task or keyword into Filter, such as undo, stash, last commit or upstream. Every word must appear in the command, its description or its topic.
  2. Or choose a Topic: Setup, Basics, Branches, Remotes, History, Undo, Stash, Tags or Advanced. Leave it on All topics to search everything.
  3. Read the Command and What it does columns. Words in angle brackets, such as <branch>, are placeholders.
  4. Download the list as git-cheatsheet.csv to keep with your team’s docs.

What it does and when to use it

Most Git work uses a small set of commands, but the ones you need rarely, such as undoing a commit, renaming a branch or deleting a remote branch, are easy to forget and risky to guess. This cheat sheet is organised by intent, so you can search for what you want to happen rather than the exact flag. It suits beginners learning the daily loop of status, add, commit and push, and experienced developers who need the exact form of rebase -i or stash apply stash@{1}.

For writing commit messages in a consistent format, use the Conventional Commit Generator. To keep build output out of the repository, the Gitignore Generator writes a starting .gitignore.

How it works

The list holds 62 commands in nine topics: Setup 6, Basics 9, Branches 12, Remotes 9, History 7, Undo 7, Stash 5, Tags 3 and Advanced 4. It uses current command names, git switch and git restore, alongside long-standing ones such as git reset. Your filter is split into words, each matched without regard to case, then the topic menu narrows the result. Nothing is sent anywhere and no Git commands run.

Worked examples

Undo something. Filter undo returns 7 rows, all in the Undo topic, including:

git reset --soft HEAD~1 | Undo the last commit, keep its changes staged. | Undo
git revert <commit> | Create a new commit that undoes a commit — safe on shared branches. | Undo

Working with a remote. Topic Remotes with an empty filter returns Showing: 9 of 62 commands, from git remote -v to git push origin --delete <branch>.

A safe force push. Filter force finds two commands: git branch -d <name> (whose note says -D forces deletion) and git push --force-with-lease.

Limits and tips

  • Each row is one common form. Run git help <command> or git <command> -h for all options.
  • Commands that rewrite history (rebase, commit --amend, reset) are fine on your own branch but need care once others have pulled it.
  • To compare two versions of a file outside Git, use the Diff Checker. For shell commands around Git, see the Linux Commands Ref.

Frequently asked questions

How do I undo the last commit but keep my work?
Run git reset --soft HEAD~1 to keep the changes staged, or git reset HEAD~1 to keep them as unstaged edits. If the commit is already pushed to a shared branch, use git revert instead so you do not rewrite history others have.
What is the difference between git switch, git restore and git checkout?
Git 2.23 split checkout into two clearer commands. git switch changes branches, and git restore discards or unstages file changes. git checkout still works for both.
Why use --force-with-lease instead of --force?
Both overwrite the remote branch, but --force-with-lease refuses if someone else pushed since your last fetch, so you do not delete their commits by accident.
Which commands lose work?
git reset --hard, git clean with -f, git restore on a modified file and git stash drop discard changes that may not be recoverable. The table marks reset --hard as destructive, and git clean -n previews what clean would delete.
Does the cheat sheet run Git?
No. It is a searchable list. Copy a command into your own terminal and replace placeholders such as <branch> and <commit>.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close