HomeGit Cheat Sheet

Git Cheat Sheet

Online Git cheat sheet with categorized commands for config, init, commit, reset, and branch tasks, plus one-click copy for daily workflows.

Command Categories

Core Workflow
Remote Collaboration
Repository Maintenance
Advanced & Recovery

Visible Commands

122

Risky Commands

29

Quick Reference

Configuration

3

Set global identity

git config --global user.name "[name]"
git config --global user.email "[email]"

List all config values

git config --list

Show a single config value

git config user.name

Get Started

3

Create a Git repository

git init

Clone an existing repository

git clone [url]

Clone a specific branch

git clone -b [branch-name] [url]

Status & Review

4

Check working tree status

git status

Show unstaged changes

git diff

Show staged changes

git diff --staged

Show the latest commit details

git show HEAD

Staging

4

Stage all changes

git add .

Stage a specific file

git add [file]

Unstage a specific file

git restore --staged [file]

Discard working tree changes for a file

Risky
git restore [file]

Commit

4

Commit staged changes

git commit -m "[commit message]"

Commit all tracked changes

git commit -am "[commit message]"

Amend the last commit without changing message

Risky
git commit --amend --no-edit

Amend the last commit message

Risky
git commit --amend -m "[commit message]"

Branch

8

List local branches

git branch

List local and remote branches

git branch -a

Create a new branch

git branch [branch-name]

Switch to a branch

git switch [branch-name]

Create and switch to a branch

git switch -c [branch-name]

Delete a merged branch

git branch -d [branch-name]

Force delete a branch

Risky
git branch -D [branch-name]

Rename the current branch

git branch -m [new-branch-name]

Remote

4

List remotes

git remote -v

Add a remote repository

git remote add origin [url]

Change remote URL

git remote set-url origin [url]

Remove a remote

Risky
git remote remove origin

Sync

6

Fetch updates from remote

git fetch origin

Pull and merge a branch

git pull origin [branch-name]

Pull with rebase

git pull --rebase origin [branch-name]

Push to a remote branch

git push origin [branch-name]

Push and set upstream

git push -u origin [branch-name]

Force push with lease protection

Risky
git push --force-with-lease origin [branch-name]

History & Diff

4

Show compact commit graph

git log --oneline --graph --decorate --all

Show commit history for a file

git log -- [file]

Show line authorship for a file

git blame [file]

Show reflog history

git reflog

Bundle

4

Create a full repository bundle

git bundle create repo.bundle --all

Verify a bundle file

git bundle verify repo.bundle

Clone from a bundle

git clone repo.bundle [dir-name]

Pull updates from a bundle

git pull repo.bundle [branch-name]

Archive

3

Export current branch as ZIP archive

git archive --format=zip --output=project.zip HEAD

Export a tag archive

git archive --format=tar.gz --output=release.tar.gz [tag-name]

Export a specific subdirectory

git archive --format=zip --output=folder.zip HEAD:[path]

Notes

5

List commit notes

git notes list

Add a note to current commit

git notes add -m "[note]"

Show notes for a commit

git notes show [commit-hash]

Append note content

git notes append -m "[note]" [commit-hash]

Remove notes for a commit

Risky
git notes remove [commit-hash]

Filter Repo

4

Analyze repository history structure

git filter-repo --analyze

Remove a path from history

Risky
git filter-repo --path [path] --invert-paths --force

Keep only a path in history

Risky
git filter-repo --path [path] --force

Replace sensitive text across history

Risky
git filter-repo --replace-text replacements.txt --force

Bisect

4

Start bisect session

git bisect start

Mark current commit as bad

git bisect bad

Mark a commit as good

git bisect good [commit-hash]

Reset and end bisect session

git bisect reset

Repo Check

4

Check repository object integrity

git fsck

Show unreachable objects

git fsck --unreachable

Run a full repository check

git fsck --full

Clean up and compact repository objects

Risky
git gc --prune=now

Maintenance

4

Start background maintenance

git maintenance start

Run automatic maintenance

git maintenance run --auto

Register repository for maintenance

git maintenance register

Stop background maintenance

git maintenance stop

Rebase

4

Rebase current branch onto target branch

Risky
git rebase [branch-name]

Continue an in-progress rebase

Risky
git rebase --continue

Skip the current conflicted commit

Risky
git rebase --skip

Abort the current rebase

git rebase --abort

Replace

4

Replace one object reference with another

Risky
git replace [old-object] [new-object]

List replace refs

git replace -l

Edit a replace object

Risky
git replace --edit [object-id]

Delete a replace ref

Risky
git replace -d [object-id]

Rerere

5

Enable rerere conflict reuse

git config rerere.enabled true

Show current rerere status

git rerere status

Show rerere conflict diff

git rerere diff

Forget conflict resolution for a path

Risky
git rerere forget [path]

Clear all rerere records

Risky
git rerere clear

Credentials

5

Configure Git Credential Manager

git config --global credential.helper manager-core

Configure in-memory credential cache

git config --global credential.helper cache

Approve credentials for helper storage

git credential approve

Fill matching credentials

git credential fill

Reject matching credentials

Risky
git credential reject

Sparse Checkout

4

Initialize sparse checkout

git sparse-checkout init --cone

Set included directories

git sparse-checkout set [path1] [path2]

Add another included path

git sparse-checkout add [path]

Disable sparse checkout

git sparse-checkout disable

Stash

5

Save changes to stash

git stash push -m "[message]"

List stash entries

git stash list

Apply and drop the latest stash

git stash pop

Apply a specific stash and keep it

git stash apply stash@{0}

Drop a specific stash entry

Risky
git stash drop stash@{0}

Tag

5

List tags

git tag

Create a lightweight tag

git tag [tag-name]

Create an annotated tag

git tag -a [tag-name] -m "[tag message]"

Push a specific tag

git push origin [tag-name]

Push all tags

git push origin --tags

Hooks

4

Set a custom hooks directory

git config core.hooksPath .githooks

Show current hooks path

git config core.hooksPath

Unset custom hooks path

Risky
git config --unset core.hooksPath

Make a hook script executable

chmod +x .githooks/pre-commit

Submodule

4

Add a submodule

git submodule add [url] [path]

Init and fetch all submodules

git submodule update --init --recursive

Update submodules to remote latest

git submodule update --remote --recursive

Show submodule status

git submodule status

Worktree

4

List worktrees

git worktree list

Create a worktree for a new branch

git worktree add ../[dir-name] -b [branch-name]

Remove a worktree

Risky
git worktree remove ../[dir-name]

Prune stale worktree records

git worktree prune

Rollback & Recovery

6

Undo the most recent commit and keep changes

Risky
git reset HEAD~1

Soft reset the latest commit

Risky
git reset --soft HEAD~1

Undo the N most recent commits and keep changes

Risky
git reset HEAD~N

Undo the latest commit and discard changes

Risky
git reset HEAD~1 --hard

Revert a commit with a new commit

git revert [commit-hash]

Reset the current branch to remote state

Risky
git fetch origin
git reset --hard origin/[branch-name]

Miscellaneous

4

Rename local master to main

git branch -m master main

Cherry-pick a commit

git cherry-pick [commit-hash]

Merge a branch into current branch

git merge [branch-name]

Remove untracked files and directories

Risky
git clean -fd


Documentation

About Git Cheat Sheet

This tool organizes common Git commands for configuration, status checks, staging, commits, branches, remotes, sync, history, bundles, archives, notes, filter-repo cleanup, bisect, repository checks, maintenance, rebase, replace refs, rerere conflict reuse, credential management, sparse checkout, tags, hooks, submodules, worktrees, stash, and rollback recovery so you can look them up and copy them quickly during development.

Key Features

  • Categorized reference: Commands are grouped into config, status, staging, commit, branch, remote, sync, history, bundle, archive, notes, filter repo, bisect, repo check, maintenance, rebase, replace, rerere, credentials, sparse checkout, tag, hooks, submodule, worktree, stash, and recovery sections.
  • One-click copy: Copy a single command or all commands currently shown by your filters.
  • Keyword filter: Search both command titles and command text to find the right action faster.
  • Risk marking: Commands such as reset, amend, and --hard are highlighted as risky.

How To Use

  1. Switch to the command category you need from the top tabs.
  2. Use the keyword filter if you want to narrow the list further.
  3. Review the command, then copy it and paste it into your terminal.
  4. Check repository status before using history-rewrite or hard reset commands.

Use Cases

  • Quick lookup while learning common Git commands.
  • Double-checking commit, push, branch, and remote commands in team workflows.
  • Temporary reference when fixing mistaken commits, tag releases, or remote sync issues.

FAQ

Does this tool run Git commands directly?

No. It only shows and copies commands. It does not access your repository or execute terminal operations.

Why are some commands marked as risky?

Because amend, reset, and --hard can rewrite history or discard changes, so they should be reviewed before use.