Skip to content
ZeroServer.tools

Git Cheat Sheet

Essential Git commands organized by workflow stage with instant search and copy.

Total Commands58
Filtered Match58
Active CategoryAll Categories
Batch Action
Quick terms:
Showing 58 Git commands.

Setup & Config

6 commands
git config --global user.name "Name"

Set global username

git config --global user.email "email"

Set global email

git config --list

List all config settings

git init

Initialize a new local repository

git clone <url>

Clone a remote repository

git clone <url> --depth 1

Shallow clone (latest commit only)

Staging & Committing

10 commands
git status

Show working tree status

git add <file>

Stage a specific file

git add .

Stage all changes

git add -p

Interactively stage hunks

git commit -m "message"

Commit with a message

git commit --amend

Amend the last commit

git diff

Show unstaged changes

git diff --staged

Show staged changes

git reset HEAD <file>

Unstage a file

git restore <file>

Discard working tree changes

Branching & Merging

10 commands
git branch

List local branches

git branch -a

List all branches (local + remote)

git branch <name>

Create a new branch

git checkout <branch>

Switch to a branch

git checkout -b <branch>

Create and switch to new branch

git switch -c <branch>

Create and switch (modern syntax)

git merge <branch>

Merge a branch into current

git rebase <branch>

Rebase current onto branch

git branch -d <branch>

Delete a merged branch

git branch -D <branch>

Force-delete a branch

Remote

8 commands
git remote -v

List remotes with URLs

git remote add origin <url>

Add a remote named origin

git fetch

Fetch all remote changes (no merge)

git pull

Fetch and merge remote changes

git pull --rebase

Fetch and rebase instead of merge

git push origin <branch>

Push branch to remote

git push -u origin <branch>

Push and set upstream

git push --force-with-lease

Safe force push

Stash

6 commands
git stash

Stash current changes

git stash pop

Apply and remove latest stash

git stash list

List all stashes

git stash apply stash@{n}

Apply a specific stash

git stash drop stash@{n}

Delete a specific stash

git stash push -m "label"

Stash with a label

Log & History

7 commands
git log

Show commit history

git log --oneline

Compact one-line history

git log --oneline --graph --all

Branch graph

git log -p

Show patches (diffs) with commits

git blame <file>

Show who changed each line

git show <commit>

Show a specific commit

git log --author="Name"

Filter by author

Undoing & Fixing

7 commands
git revert <commit>

Create a revert commit

git reset --soft HEAD~1

Undo last commit, keep staged

git reset --mixed HEAD~1

Undo last commit, keep files

git reset --hard HEAD~1

Undo last commit and discard changes

git clean -fd

Remove untracked files and dirs

git cherry-pick <commit>

Apply a commit from another branch

git reflog

Show all recent HEAD movements

Tags

4 commands
git tag v1.0.0

Create a lightweight tag

git tag -a v1.0.0 -m "msg"

Create an annotated tag

git push origin --tags

Push all tags to remote

git tag -d v1.0.0

Delete a local tag

How to use this Git cheat sheet

This reference covers essential Git commands every software developer uses daily. It is structured by developer workflow stages — from initial setup and configuration through branching, committing, remote synchronization, stashing, and undoing accidental mistakes. Use the quick filter chips or live search box to rapidly lookup commands by command syntax or intended description. Click the copy icon next to any command to instantly send it to your clipboard for usage in your terminal. For in-depth CLI documentation on any command, run git help <command> directly in your system terminal.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Finding a command you use rarely without searching.
  • Checking the exact flag for an operation before running it.
  • Learning a workflow by seeing its commands grouped.
  • Confirming a destructive command's syntax before using it.
  • Finding the safer alternative to a command you were about to run.

Frequently Asked Questions

What is the difference between reset, revert and checkout?
`reset` moves the branch pointer and can discard commits, `revert` creates a new commit undoing an old one, and `checkout`/`switch` change what you have checked out. Only `revert` is safe on history others have pulled.
When is force-pushing acceptable?
On a branch only you use, and then with `--force-with-lease` so it refuses if someone else pushed. On a shared branch it rewrites history under collaborators, which is how work gets lost.
What does the stash actually do?
Saves uncommitted changes to a stack and cleans the working tree. It is easy to forget — `git stash list` is worth checking, because stashes survive branch switches and are invisible in normal status output.
How do I recover a commit I lost?
`git reflog` records where HEAD has been, including commits no branch points at any more. Almost anything committed can be recovered from there for a couple of weeks before garbage collection.
Merge or rebase?
Merge preserves what actually happened; rebase produces a linear history that is easier to read. The practical rule is to rebase your own unpushed work and merge anything already shared.

Common errors and gotchas

  • Running a destructive command from a cheat sheet without understanding it, `reset --hard` above all.
  • Assuming a command is safe because it is short, where `checkout` on a file discards changes silently.
  • Force-pushing to a shared branch, which rewrites history other people have.
  • Confusing `reset`, `revert` and `restore`, which do very different things.
  • Copying a command with a placeholder left in, which then acts on the wrong ref.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate