T
DataToolings

Git Commands Cheat Sheet

A searchable Git commands cheat sheet covering init, clone, branch, merge, rebase, stash, and more. Copy any command instantly.

57 commands

git init
setup

Initialize a new local repository

git clone <url>
setup

Clone a remote repository locally

git config --global user.name "<name>"
setup

Set global username

git config --global user.email "<email>"
setup

Set global email

git status
info

Show working tree status

git log
info

Show commit history

git log --oneline
info

Show compact commit history

git log --graph --oneline --all
info

Show branch graph

git diff
info

Show unstaged changes

git diff --staged
info

Show staged changes

git show <commit>
info

Show details of a commit

git blame <file>
info

Show who changed each line

git add <file>
staging

Stage a specific file

git add .
staging

Stage all changes

git add -p
staging

Interactively stage hunks

git commit -m "<message>"
staging

Commit with a message

git commit --amend
staging

Amend the last commit

git reset HEAD <file>
staging

Unstage a file

git branch
branch

List all local branches

git branch -a
branch

List all branches (local + remote)

git branch <name>
branch

Create a new branch

git checkout <branch>
branch

Switch to a branch

git checkout -b <branch>
branch

Create and switch to a new branch

git switch <branch>
branch

Switch to a branch (modern syntax)

git switch -c <branch>
branch

Create and switch to a new branch (modern)

git branch -d <branch>
branch

Delete a merged branch

git branch -D <branch>
branch

Force delete a branch

git merge <branch>
merge

Merge a branch into current

git merge --no-ff <branch>
merge

Merge with a merge commit

git rebase <branch>
merge

Rebase current branch onto another

git rebase -i HEAD~<n>
merge

Interactive rebase last N commits

git cherry-pick <commit>
merge

Apply a specific commit to current branch

git remote -v
remote

List remote connections

git remote add origin <url>
remote

Add a remote named origin

git fetch
remote

Download remote changes without merging

git pull
remote

Fetch and merge remote changes

git pull --rebase
remote

Fetch and rebase remote changes

git push origin <branch>
remote

Push branch to remote

git push -u origin <branch>
remote

Push and set upstream tracking

git push --force-with-lease
remote

Safe force push (checks remote state)

git stash
stash

Stash current changes

git stash push -m "<message>"
stash

Stash with a description

git stash list
stash

List all stashes

git stash pop
stash

Apply and remove the latest stash

git stash apply stash@{n}
stash

Apply a specific stash

git stash drop stash@{n}
stash

Delete a specific stash

git revert <commit>
undo

Create a new commit that undoes a commit

git reset --soft HEAD~1
undo

Undo last commit, keep changes staged

git reset --mixed HEAD~1
undo

Undo last commit, keep changes unstaged

git reset --hard HEAD~1
undo

Undo last commit and discard changes

git restore <file>
undo

Discard unstaged changes in a file

git clean -fd
undo

Remove untracked files and directories

git tag
tags

List all tags

git tag <name>
tags

Create a lightweight tag

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

Create an annotated tag

git push origin --tags
tags

Push all tags to remote

git tag -d <name>
tags

Delete a local tag

Related Developer Tools

What is Git Commands Cheat Sheet?

Git Commands Cheat Sheet is a free, searchable reference of the most commonly used Git commands. Browse commands by category — setup, branching, merging, remote, stash, and more — and copy any command with one click.

How to Use Git Commands

  1. Search for a command by name or description
  2. Filter by category using the buttons above
  3. Click the copy button to copy the command to your clipboard
  4. Paste it into your terminal and replace placeholders like <branch>

Features

  • 57 commands across 9 categories
  • Search by command name or description
  • Filter by category: setup, branch, merge, remote, stash, undo, tags
  • One-click copy for each command

FAQ

What do the angle brackets mean?

Angle brackets like <branch> are placeholders. Replace them with your actual value, e.g. git checkout main.

What is the difference between git fetch and git pull?

git fetch downloads remote changes but doesn't apply them. git pull fetches and then merges (or rebases) them into your current branch.

What is the safest way to undo a commit?

git revert is the safest — it creates a new commit that undoes the changes without rewriting history. Use git reset only on commits that haven't been pushed to a shared remote.