All Cheatsheets

Git Cheatsheet

Git commands for everyday workflow, branching, remote operations, undo, and advanced usage.

6 sections63 commandsClick any row to copy

Setup & Init

git init
git clone https://github.com/user/repo.git
git clone https://github.com/user/repo.git --depth=1
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor vim
git config --list

Initialize new git repository in current dir

Clone remote repository

Shallow clone (only latest commit, faster)

Set global username

Set global email

Set default editor

Show all git config values

Daily Workflow

git status
git add file.txt
git add .
git add -p
git commit -m "feat: add login endpoint"
git commit -am "fix: typo in config"
git diff
git diff --staged
git log --oneline --graph --all
git log --oneline -10
git show HEAD
git show abc1234

Show modified, staged, untracked files

Stage specific file

Stage all changes in current directory

Interactively stage chunks of changes

Commit staged changes with message

Stage tracked files + commit in one step

Show unstaged changes

Show staged changes (what will be committed)

Compact visual branch graph

Last 10 commits, one line each

Show last commit changes

Show specific commit changes

Branching

git branch
git branch -a
git branch feature/login
git switch -c feature/login
git checkout feature/login
git merge feature/login
git merge --no-ff feature/login
git rebase main
git rebase -i HEAD~3
git branch -d feature/login
git branch -D feature/login
git cherry-pick abc1234

List local branches

List local and remote branches

Create new branch (stay on current)

Create and switch to new branch

Switch to existing branch

Merge branch into current branch

Merge with explicit merge commit (no fast-forward)

Rebase current branch onto main

Interactive rebase — squash/reword last 3 commits

Delete merged branch

Force delete branch (even if unmerged)

Apply specific commit onto current branch

Remote

git remote -v
git remote add origin https://github.com/user/repo.git
git fetch
git fetch --prune
git pull
git pull --rebase
git push origin main
git push -u origin feature/login
git push origin --delete feature/login
git push --tags

List remote connections with URLs

Add remote named origin

Download remote changes without merging

Fetch + remove stale remote-tracking branches

Fetch + merge remote changes into current branch

Fetch + rebase instead of merge (cleaner history)

Push local commits to remote

Push new branch + set upstream tracking

Delete remote branch

Push all local tags to remote

Undo & Fix

git restore file.txt
git restore .
git restore --staged file.txt
git revert HEAD
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
git stash
git stash pop
git stash list
git stash apply stash@{2}
git stash drop stash@{0}

Discard unstaged changes in file

Discard all unstaged changes

Unstage file (keep changes)

Revert last commit with new undo commit (safe for shared branches)

Undo last commit — keep changes staged

Undo last commit — keep changes unstaged

⚠️ Undo last commit and DISCARD all changes

Stash current changes temporarily

Apply most recent stash and remove it

Show all stashed changesets

Apply specific stash without removing it

Delete specific stash

Tags & Advanced

git tag v1.0.0
git tag -a v1.0.0 -m "Release v1.0.0"
git tag
git push origin v1.0.0
git push origin --tags
git blame file.txt
git bisect start
git shortlog -sn
git clean -fd
git reflog

Create lightweight tag at current commit

Create annotated tag with message

List all tags

Push specific tag to remote

Push all tags to remote

Show who changed each line and when

Start binary search to find bug-introducing commit

Commit count per author, sorted

Remove untracked files and directories

Show history of HEAD movements (recover lost commits)