Skip to content

Git Cheatsheet

Search a categorized reference of common Git commands - branching, merging, undoing changes, and more.

Category: development
Use Case: Looking Up a Git Command You Forgot, Learning Git Fundamentals, Finding the Safe Way to Undo Something
Privacy: 100% browser-based

Setup

git init

Create a new local Git repository

git clone <url>

Clone a remote repository locally

git config --global user.name "Name"

Set your global commit author name

Basics

git status

Show the working tree status

git add <file>

Stage a file's changes

git add .

Stage all changed files in the current directory

git commit -m "message"

Commit staged changes with a message

git commit --amend

Modify the most recent commit

git diff

Show unstaged changes

git diff --staged

Show staged changes

Branching

git branch

List local branches

git branch <name>

Create a new branch

git checkout <branch>

Switch to a branch

git checkout -b <branch>

Create and switch to a new branch

git switch <branch>

Switch to a branch (modern alternative to checkout)

git branch -d <branch>

Delete a merged local branch

git branch -D <branch>

Force-delete a local branch

Merging

git merge <branch>

Merge a branch into the current branch

git rebase <branch>

Reapply commits on top of another branch

git rebase -i HEAD~n

Interactively rebase the last n commits

git cherry-pick <commit>

Apply a specific commit onto the current branch

Remote

git remote -v

List configured remotes

git remote add origin <url>

Add a new remote named origin

git fetch

Download objects and refs from a remote

git pull

Fetch and merge changes from a remote

git pull --rebase

Fetch and rebase local commits on top

git push

Push local commits to a remote

git push -u origin <branch>

Push and set the upstream tracking branch

git push --force-with-lease

Force-push safely, aborting if the remote has new commits

Undoing

git restore <file>

Discard unstaged changes to a file

git restore --staged <file>

Unstage a file, keeping its changes

git reset --soft HEAD~1

Undo the last commit, keeping changes staged

git reset --mixed HEAD~1

Undo the last commit, keeping changes unstaged

git reset --hard HEAD~1

Undo the last commit and discard its changes

git revert <commit>

Create a new commit that undoes a previous commit

Stash

git stash

Temporarily shelve uncommitted changes

git stash pop

Reapply and remove the most recent stash

git stash list

List all stashed changes

git stash drop

Delete the most recent stash without applying it

Inspecting

git log

Show commit history

git log --oneline --graph

Show a compact, graphical commit history

git show <commit>

Show the details and diff of a specific commit

git blame <file>

Show who last modified each line of a file

Tags

git tag <name>

Create a lightweight tag on the current commit

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

Create an annotated tag

git push origin <tag>

Push a specific tag to the remote

Recommended Settings

Pro Tips

  • git restore and git switch are newer, clearer replacements for some checkout use cases - both do exactly what their names suggest
  • Prefer git push --force-with-lease over a plain --force, since it aborts if someone else has pushed new commits you don't have yet
  • git reset --hard permanently discards changes - always double check you don't need them before running it
  • Search by category name (like 'stash' or 'undo') to quickly find a related group of commands

Most Popular

Most developers search this for the exact syntax of an undo or rebase command they use infrequently

When to Use This Tool

Looking Up a Git Command You Forgot

Quickly find the exact syntax for a command you don't use often.

Learning Git Fundamentals

Browse commands by category to build a mental model of core Git workflows.

Finding the Safe Way to Undo Something

Compare reset, revert, and restore to pick the safest way to undo a change.

Onboarding New Team Members

Share a categorized reference to help teammates get comfortable with Git.

How It Works

1

Search a curated reference list of common Git commands grouped by workflow category

2

Filter results instantly as you type, matching against the command, description, and category

3

Copy any command directly to your clipboard for use in your terminal

100% Private

Files never leave your device. All processing happens locally in your browser.

Lightning Fast

Powered by Client-side static reference lookup for optimal performance on modern browsers.

Open Source

Built with verified, open-source libraries. Fully transparent.

Frequently Asked Questions

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

Merge combines two branches' histories with a new merge commit, preserving the original commit history. Rebase replays your commits on top of another branch, producing a linear history but rewriting commit hashes.

When should I use reset vs revert?

Use revert on commits that have already been pushed and shared, since it creates a new commit and doesn't rewrite history. Reset is safer for local, unpushed commits since it can rewrite history.

Is this list exhaustive?

This covers the most frequently used Git commands and flags for everyday development. Git has many more advanced commands and options not listed here.

Is my search sent anywhere?

No. Searching happens entirely locally against a static list in your browser.