Git Cheatsheet

Git Cheatsheet
git init

Initialize a new git repository

Setup
git clone <url>

Clone a remote repository

Setup
git config --global user.name "Name"

Set your global username

Setup
git config --global user.email "email"

Set your global email

Setup
git config --list

Show all configuration settings

Setup
git remote add origin <url>

Add a remote repository

Setup
git remote -v

List remote repositories

Setup
git branch

List local branches

Branch
git branch -a

List all branches (local + remote)

Branch
git branch <name>

Create a new branch

Branch
git branch -d <name>

Delete a branch (safe)

Branch
git branch -D <name>

Force delete a branch

Branch
git branch -m <old> <new>

Rename a branch

Branch
git checkout <branch>

Switch to a branch

Branch
git checkout -b <name>

Create and switch to new branch

Branch
git switch <branch>

Switch to a branch (modern)

Branch
git switch -c <name>

Create and switch (modern)

Branch
git status

Show working tree status

Commit
git add <file>

Stage a specific file

Commit
git add .

Stage all changes

Commit
git add -p

Stage changes interactively (by hunk)

Commit
git commit -m "message"

Commit staged changes with message

Commit
git commit -am "message"

Stage tracked files and commit

Commit
git commit --amend

Amend the last commit

Commit
git diff

Show unstaged changes

Commit
git diff --staged

Show staged changes

Commit
git diff <branch1> <branch2>

Compare two branches

Commit
git push

Push commits to remote

Remote
git push -u origin <branch>

Push and set upstream branch

Remote
git push --force

Force push (destructive!)

Remote
git pull

Fetch and merge remote changes

Remote
git pull --rebase

Fetch and rebase instead of merge

Remote
git fetch

Download remote changes without merging

Remote
git fetch --prune

Fetch and remove deleted remote branches

Remote
git push origin --delete <branch>

Delete a remote branch

Remote
git stash

Stash current changes

Stash
git stash push -m "message"

Stash with a description

Stash
git stash list

List all stashes

Stash
git stash pop

Apply and remove latest stash

Stash
git stash apply

Apply latest stash without removing

Stash
git stash drop

Delete latest stash

Stash
git stash clear

Delete all stashes

Stash
git log

Show commit history

Log
git log --oneline

Show compact commit history

Log
git log --graph --oneline

Show commit graph

Log
git log -n 5

Show last 5 commits

Log
git log --author="name"

Filter commits by author

Log
git log -- <file>

Show commits for a specific file

Log
git blame <file>

Show who changed each line

Log
git show <commit>

Show details of a commit

Log
git merge <branch>

Merge a branch into current

Merge
git merge --no-ff <branch>

Merge with a merge commit (no fast-forward)

Merge
git merge --abort

Abort a merge in progress

Merge
git rebase <branch>

Rebase current branch onto another

Merge
git rebase --abort

Abort a rebase in progress

Merge
git cherry-pick <commit>

Apply a specific commit to current branch

Merge
git restore <file>

Discard changes in working directory

Undo
git restore --staged <file>

Unstage a file

Undo
git reset HEAD~1

Undo last commit, keep changes staged

Undo
git reset --hard HEAD~1

Undo last commit and discard changes

Undo
git revert <commit>

Create a new commit that undoes a commit

Undo
git clean -fd

Remove untracked files and directories

Undo
git reflog

Show history of HEAD changes (recovery)

Undo
git tag

List all tags

Tags
git tag <name>

Create a lightweight tag

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

Create an annotated tag

Tags
git push --tags

Push all tags to remote

Tags
git tag -d <name>

Delete a local tag

Tags
Showing 68 of 68 commands

Git Commands Cheatsheet

A comprehensive, searchable reference of the most useful git commands. Filter by category (setup, branch, commit, remote, stash, log, merge, undo, tags) or search by keyword. Click to copy any command.

About this cheatsheet

This git cheatsheet covers the most common git operations organized by workflow category. Perfect as a quick reference while coding.

  • 65+ git commands with descriptions
  • Filter by category (Setup, Branch, Commit, Remote, Stash, Log, Merge, Undo, Tags)
  • Full-text search across commands and descriptions
  • One-click copy to clipboard
  • Works offline — all data is in the page

100% free. No signup required. No data collected or sent anywhere.

Explore All Tools