Git Cheat Sheet

Searchable reference of the Git commands you forget — commit, branch, merge, rebase, stash and undo — in plain language with one-click copy. Free, no signup.

Showing 65 of 65 commands

Setup & Config

git init
Create an empty Git repository in the current folder.
git clone <url>
Download a remote repository and its full history.
git config --global user.name "Your Name"
Set the author name attached to your commits.
git config --global user.email "you@example.com"
Set the author email attached to your commits.
git config --list
List all effective configuration values.

Staging

git status
Show which files are staged, modified, or untracked.
git add <file>
Stage a specific file for the next commit.
git add .
Stage every change under the current directory.
git add -p
Interactively choose which chunks (hunks) to stage.
git restore --staged <file>
Unstage a file while keeping its edits.
git rm <file>
Remove a file and stage the deletion.

Commit

git commit -m "message"
Record staged changes with a short message.
git commit -am "message"
Stage all tracked files and commit in one step.
git commit --amend
Replace the last commit (edit message or add files).
git commit --amend --no-edit
Add staged changes to the last commit, keep its message.
git commit --allow-empty -m "message"
Create a commit with no changes (e.g. to trigger CI).

Branches

git branch
List local branches.
git branch <name>
Create a new branch at the current commit.
git switch <name>
Switch to an existing branch.
git switch -c <name>
Create a new branch and switch to it.
git checkout <branch>
Classic way to switch branches (pre-git switch).
git branch -d <name>
Delete a branch that has already been merged.
git branch -m <old> <new>
Rename a branch.

Merge & Rebase

git merge <branch>
Merge another branch into the current one.
git merge --no-ff <branch>
Merge and always create a merge commit.
git rebase <branch>
Reapply your commits on top of another branch.
git rebase -i <base>
Interactively edit, squash, or reorder commits.
git rebase --continue
Resume a rebase after resolving conflicts.
git rebase --abort
Cancel a rebase and return to the original state.
git cherry-pick <commit>
Apply a single commit onto the current branch.

Remote

git remote -v
List remote repositories and their URLs.
git remote add <name> <url>
Add a new remote repository.
git fetch <remote>
Download remote changes without merging them.
git pull
Fetch and merge changes from the tracked branch.
git push
Upload local commits to the remote branch.
git push -u origin <branch>
Push and set the upstream tracking branch.
git push --force-with-lease
Force-push safely, refusing if others pushed first.

Undo & Reset

git restore <file>
Discard uncommitted changes in a file.
git reset --soft HEAD~1
Undo the last commit, keep its changes staged.
git reset --mixed HEAD~1
Undo the last commit, keep its changes unstaged.
git reset --hard HEAD~1
Undo the last commit and discard its changes.
git reset HEAD~<n>
Undo the N most recent commits and keep their changes.
git fetch origin git reset --hard origin/<branch>
Both steps: throw away local commits and match the remote branch exactly.
git revert <commit>
Create a new commit that undoes a past commit.
git clean -fd
Delete untracked files and directories.
git reflog
Show where HEAD has been — recover lost commits.

Stash

git stash
Save uncommitted changes and revert to a clean tree.
git stash -u
Stash changes including untracked files.
git stash list
List all stashed changesets.
git stash pop
Reapply the latest stash and remove it from the list.
git stash apply
Reapply a stash but keep it in the list.
git stash drop
Delete the latest stash without applying it.

Log & Diff

git log
Show the commit history.
git log --oneline
Show history as one compact line per commit.
git log --graph --oneline --all
Show a visual graph of branches and merges.
git diff
Show unstaged changes against the last commit.
git diff --staged
Show changes that are staged for the next commit.
git show <commit>
Show the metadata and diff of a single commit.
git blame <file>
Show who last changed each line of a file.

Tags

git tag
List all tags.
git tag <name>
Create a lightweight tag at the current commit.
git tag -a <name> -m "message"
Create an annotated tag with a message.
git push origin <tag>
Push a specific tag to the remote.
git push --tags
Push all local tags to the remote.
git tag -d <name>
Delete a local tag.

🔒 Runs in your browser — nothing is uploaded.

Every Git command you forget, one search away

Type part of a command or what you want to do — like rebase, stash or undo — and the list filters instantly. Commands are grouped by task: setup, staging, commit, branches, merge and rebase, remote, undo, stash, log and tags. Each row has a short plain-language note and a one-click Copy button. It is a static reference that runs entirely in your browser, so nothing you type is uploaded.

Reset vs revert, merge vs rebase

The commands people mix up are here side by side: git reset --soft, --mixed and --hard for undoing commits, git revert for undoing a commit safely on a shared branch, and git rebase versus git merge for integrating branches. Search "undo" to compare the safe options, or "push" to see remote and tag pushes together.

Frequently asked questions

What is the difference between git reset and git revert?

git reset moves the branch pointer and can drop commits or changes locally, so it rewrites history. git revert adds a new commit that undoes an earlier one, which is safe on a branch other people have already pulled.

When should I use git rebase instead of git merge?

Use rebase to keep a linear history by replaying your commits on top of the latest branch, which is handy before opening a pull request. Use merge to combine branches while preserving the exact history, especially on shared branches where rewriting is risky.

How do I undo my last commit but keep the changes?

Run git reset --soft HEAD~1 to remove the commit and leave everything staged, or git reset --mixed HEAD~1 to keep the changes but unstage them.

Is anything I search uploaded to a server?

No. The command list is static data bundled with the page and the search runs entirely in your browser, so nothing you type leaves your device.