Git Command Cheat Sheet

A searchable, filterable reference of common Git commands: setup, branching, remotes, undo, stash, and more.

Input data is processed in your browser
Data is never sent to a server

Tool

Setup

git init

Initialize the current directory as a new Git repository

git clone <url>

Clone a remote repository to your local machine

e.g.git clone https://github.com/user/repo.git
git config --global user.name "<name>"

Set the username used for your commits globally

git config --global user.email "<email>"

Set the email used for your commits globally

Basics

git status

Show the state of the working directory and staging area

git add <file>

Add changes to the staging area

e.g.git add .
git commit -m "<message>"

Commit staged changes

git commit --amend

Modify the message or contents of the previous commit

git diff

Show the diff between the working directory and the index

git diff --staged

Show the diff between the index and HEAD

git rm <file>

Remove a file and stage the removal

git mv <old> <new>

Rename a file and stage the rename

Branching

git branch

List local branches

git branch <name>

Create a new branch without switching to it

git switch <branch>

Switch to the specified branch

git switch -c <branch>

Create a new branch and switch to it

git branch -d <branch>

Delete a branch that has already been merged

git branch -D <branch>

Force delete a branch, even if unmerged

git merge <branch>

Merge the specified branch into the current branch

git rebase <branch>

Reapply commits on top of the specified branch

Remote

git remote -v

List registered remote repositories

git remote add <name> <url>

Register a new remote repository

e.g.git remote add origin <url>
git fetch <remote>

Download changes from a remote without merging

git pull

Fetch changes from remote and merge into the current branch

git pull --rebase

Fetch changes and rebase instead of merging

git push

Push local commits to the remote repository

git push -u origin <branch>

Push and set the upstream branch on first push

git push --force-with-lease

Safely force-push without overwriting new remote changes

Undo & Reset

git restore <file>

Discard working directory changes back to HEAD

git restore --staged <file>

Unstage a staged change (undo git add)

git reset --soft HEAD~1

Undo the previous commit, keeping changes staged

git reset --mixed HEAD~1

Undo the previous commit, keeping changes unstaged (default)

git reset --hard HEAD~1

Discard the previous commit and all its changes completely

git revert <commit>

Create a new commit that undoes the specified commit

git clean -fd

Remove untracked files and directories

Stash

git stash

Temporarily shelve uncommitted changes

git stash list

List stashed changes

git stash pop

Apply the latest stash and remove it from the stack

git stash apply

Apply the latest stash, keeping it in the stack

git stash drop

Discard the latest stash

History & Inspection

git log

Show commit history

git log --oneline --graph

Show commit history as a one-line graph

git show <commit>

Show details and changes for a specific commit

git blame <file>

Show which commit last modified each line of a file

git bisect start

Start a binary search to find the commit that introduced a bug

Tags

git tag

List tags

git tag <name>

Create a lightweight tag at the current commit

git tag -a <name> -m "<message>"

Create an annotated tag

git push origin <tag>

Push the specified tag to the remote

What is the Git Command Cheat Sheet?

This is a quick reference for everyday Git commands, organized into 8 categories: setup, basics, branching, remote, undo/reset, stash, history & inspection, and tags. Search and category filters help you find the command you need right away.

Categories Covered

  • Setup (git init / clone / config)
  • Basics (add / commit / diff / rm / mv)
  • Branching (branch / switch / merge / rebase)
  • Remote (remote / fetch / pull / push)
  • Undo & Reset (restore / reset / revert / clean)
  • Stash (stash / pop / apply / drop)
  • History & Inspection (log / show / blame / bisect)
  • Tags (tag / annotated tag)

When This Comes in Handy

  • Recalling the options for a command you don’t use often
  • As an onboarding reference for new team members
  • Double-checking the difference between reset modes before running a potentially destructive command

How to Use

  1. Type a command name or keyword into the search box to filter to matching commands.
  2. Use the category buttons to show only a specific category, such as "Branching" or "Remote".
  3. Click any command card to copy the command string straight to your clipboard.

FAQ

What's the difference between git reset --soft, --mixed, and --hard?

All three undo the previous commit, but with different scope. --soft keeps your changes staged, --mixed (the default) unstages them but keeps them in the working directory, and --hard discards the changes entirely.

What's the difference between git merge and git rebase?

git merge combines two branches' histories into a single merge commit, preserving the branching history as-is. git rebase reapplies your branch's commits on top of another branch, producing a linear history. Rebasing a shared branch can rewrite history other developers depend on, so use it carefully.

Why is --force-with-lease recommended over --force when pushing?

A plain --force unconditionally overwrites whatever is on the remote. --force-with-lease only allows the push if the remote hasn't changed since you last fetched, which helps prevent accidentally wiping out someone else's work.

When should I use git stash instead of git commit?

Use git stash to temporarily shelve in-progress changes so you can switch branches, and use git commit to record a meaningful, permanent unit of change in your history. A stash is a temporary holding area, not part of your permanent history.