Git Cheatsheet - Quick Command Reference & Memo

Free online Git cheatsheet with searchable commands organized by category. Quickly find Git commands for branching, merging, rebasing, stashing, resetting, and more.

Setup & Config

git init

Initialize a new Git repository in the current directory

--bare
git clone <url>

Clone a remote repository to your local machine

--depth 1--branch <name>--recurse-submodules
git config user.name "<name>"

Set the author name for commits

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

Set the author email for commits

--global--local

Staging & Commits

git add <file>

Stage a file for the next commit

-A-p.
git commit -m "<message>"

Create a commit with a message

--amend--no-edit-a--allow-empty
git status

Show the working tree status

-s--short
git diff

Show unstaged changes

--staged--cached--stat--name-only
git log

Show commit history

--oneline--graph--all-n <number>--author=<name>

Branching & Merging

git branch

List, create, or delete branches

-a-d <branch>-D <branch>-m <new-name>
git checkout <branch>

Switch to a branch or restore files

-b <new-branch>--
git switch <branch>

Switch to a branch (modern alternative to checkout)

-c <new-branch>--detach
git merge <branch>

Merge a branch into the current branch

--no-ff--squash--abort
git rebase <branch>

Reapply commits on top of another branch

-i--onto--abort--continue

Remote

git remote -v

List remote repositories with URLs

add <name> <url>remove <name>rename <old> <new>
git fetch

Download objects and refs from a remote

--all--prune<remote>
git pull

Fetch and integrate changes from a remote branch

--rebase--no-rebase<remote> <branch>
git push

Upload local commits to a remote repository

-u origin <branch>--force--tags--delete <branch>

Stash

git stash

Temporarily save uncommitted changes

-u--include-untracked-m "<message>"
git stash pop

Apply the most recent stash and remove it from the list

git stash list

List all stashed changes

git stash drop

Remove a specific stash entry

stash@{n}
git stash apply

Apply a stash without removing it from the list

stash@{n}

Undo & Reset

git reset <file>

Unstage a file while preserving changes

--soft HEAD~1--mixed HEAD~1--hard HEAD~1
git revert <commit>

Create a new commit that undoes a previous commit

--no-commit-n
git restore <file>

Discard changes in the working directory

--staged--source=<commit>
git clean -fd

Remove untracked files and directories

-n (dry run)-x-i

Inspection

git log --oneline

Show compact commit history (one line per commit)

git log --graph --all

Visualize branch history as a graph

git show <commit>

Display details and diff of a specific commit

git blame <file>

Show who last modified each line of a file

git reflog

Show a log of all reference updates (useful for recovery)

git shortlog -sn

Summarize commit counts by author

Tags

git tag <name>

Create a lightweight tag at the current commit

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

Create an annotated tag with a message

git tag -l

List all tags

"v1.*"
git push origin <tag>

Push a specific tag to a remote

--tags
git tag -d <name>

Delete a local tag

What Is a Git Cheatsheet?

A Git cheatsheet is a quick-reference guide that lists the most commonly used Git commands organized by category. Git is the world's most popular distributed version control system, used by millions of developers to track changes, collaborate on code, and manage project history. With dozens of commands and hundreds of options, even experienced developers benefit from having a concise reference at hand. This cheatsheet covers everything from basic setup and staging to advanced workflows like interactive rebasing, stash management, and history inspection.

How to Use This Git Cheatsheet

  1. Browse commands organized into categories: Setup, Staging, Branching, Remote, Stash, Undo, Inspection, and Tags.
  2. Use the search field to filter commands by keyword — type 'rebase', 'stash', 'reset', or any part of a command or description.
  3. Each command shows the syntax, a short description, and common flags or options you can use.
  4. Click the copy button next to any command to copy it to your clipboard for immediate use in your terminal.
  5. Use the flags listed under each command to discover useful variations you might not know about.

Common Use Cases

  • Daily Development Workflow — Quickly look up commands for committing, branching, and pushing code during your daily development workflow without leaving your browser.
  • Learning Git — New to Git? Browse the organized categories to discover commands and understand what each one does, complete with common flags and options.
  • Resolving Merge Conflicts — Find the right commands for rebasing, merging, resetting, and reverting when you need to resolve conflicts or undo mistakes.
  • Code Review & Inspection — Use inspection commands like git log, git blame, and git show to review commit history, understand changes, and trace code authorship.

FAQ

What is the difference between git merge and git rebase?
Both integrate changes from one branch into another. 'git merge' creates a merge commit preserving the full history of both branches. 'git rebase' replays your commits on top of the target branch, producing a linear history. Merge is safer for shared branches; rebase is cleaner for feature branches before merging.
How do I undo the last commit?
Use 'git reset --soft HEAD~1' to undo the commit but keep changes staged. Use 'git reset --mixed HEAD~1' to undo the commit and unstage changes. Use 'git reset --hard HEAD~1' to undo the commit and discard all changes. If the commit is already pushed, use 'git revert' instead to create a safe undo commit.
What is the difference between git fetch and git pull?
'git fetch' downloads new data from a remote repository but does not integrate it into your working branch. 'git pull' is essentially 'git fetch' followed by 'git merge' — it fetches and immediately integrates the changes. Use fetch when you want to review changes before merging.

Related Tools