Git Cheatsheet - Quick Git Command Reference

Quick reference for common Git commands. Search, copy, and use Git commands instantly.

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

Set global username

git config --global user.email "email"

Set global email

git config --list

List all configurations

git config --global core.editor "vim"

Set default text editor

git config --global init.defaultBranch main

Set default branch name

git config --global alias.co checkout

Set command alias

git config --global credential.helper cache

Cache credentials

git init

Initialize a new repository

git init --bare

Initialize bare repository

git clone <url>

Clone a remote repository

git clone -b <branch> <url>

Clone specific branch

git clone --depth 1 <url>

Shallow clone (latest commit only)

git clone --recursive <url>

Clone with submodules

git status

Check working directory status

git status -s

Short status format

git add <file>

Add file to staging area

git add .

Add all changes

git add -A

Add all changes including deletions

git add -p

Interactive add (patch mode)

git rm <file>

Delete file and stage

git rm --cached <file>

Remove file from staging

git mv <old> <new>

Rename file

git commit -m "message"

Commit staged changes

git commit -am "message"

Add and commit all changes

git commit --amend

Amend last commit

git commit --amend --no-edit

Amend without changing message

git branch

List local branches

git branch -a

List all branches

git branch -r

List remote branches

git branch --merged

List merged branches

git branch <name>

Create new branch

git branch -d <name>

Delete branch

git branch -D <name>

Force delete branch

git branch -m <old> <new>

Rename branch

git checkout <branch>

Switch branch

git checkout -b <name>

Create and switch branch

git checkout --track origin/<branch>

Track remote branch

git switch <branch>

Switch branch (new)

git switch -c <name>

Create and switch (new)

git merge <branch>

Merge branch into current

git merge --no-ff <branch>

Merge with no fast-forward

git merge --squash <branch>

Squash merge (no commit)

git merge --abort

Abort merge

git rebase <branch>

Rebase onto branch

git rebase -i HEAD~3

Interactive rebase last 3 commits

git rebase --continue

Continue rebase

git rebase --abort

Abort rebase

git cherry-pick <commit>

Cherry-pick a commit

git remote -v

View remote repositories

git remote add origin <url>

Add remote repository

git remote remove <name>

Remove remote repository

git remote set-url origin <url>

Change remote URL

git fetch

Fetch from remote

git fetch --prune

Fetch and prune remote branches

git pull

Pull and merge from remote

git pull --rebase

Pull with rebase

git push

Push to remote

git push -u origin <branch>

Push and set upstream

git push --force

Force push

git push --force-with-lease

Force push with lease

git push origin --delete <branch>

Delete remote branch

git log

View commit history

git log --oneline

Compact history view

git log --oneline --graph

Compact graphical history

git log --graph --all --decorate

Full graphical history

git log --stat

Show change statistics

git log -3

Show last 3 commits

git log --author="name"

Filter by author

git log --since="1 week ago"

Filter by time

git log --grep="keyword"

Filter by commit message

git diff

View working directory changes

git diff --cached

View staged changes

git diff HEAD

View all changes

git show <commit>

Show commit details

git blame <file>

Show line-by-line author

git shortlog -sn

Author commit count

git tag

List all tags

git tag <name>

Create lightweight tag

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

Create annotated tag

git tag -d <name>

Delete local tag

git push origin <tag>

Push tag to remote

git push origin --tags

Push all tags

git push origin --delete <tag>

Delete remote tag

git stash

Stash current changes

git stash push -m "message"

Stash with message

git stash push -u

Stash including untracked

git stash list

List stashes

git stash show

Show latest stash changes

git stash pop

Pop latest stash

git stash apply

Apply stash without removing

git stash drop

Drop latest stash

git stash clear

Clear all stashes

git stash branch <name>

Create branch from stash

git reset HEAD <file>

Unstage file

git reset --soft HEAD~1

Soft reset to last commit

git reset --mixed HEAD~1

Mixed reset (default)

git reset --hard HEAD~1

Hard reset to last commit

git revert <commit>

Revert a commit

git checkout -- <file>

Discard file changes

git restore <file>

Restore file (new)

git restore --staged <file>

Unstage file (new)

git clean -n

Preview removing untracked

git clean -fd

Remove untracked files and dirs

git submodule add <url>

Add submodule

git submodule update --init

Init and update submodules

git submodule update --recursive

Update submodules recursively

git submodule deinit <path>

Remove submodule

git reflog

View reference log

git reflog show HEAD@{10}

Show specific reference

git gc

Garbage collection

git fsck

Check repository integrity

git archive -o latest.zip HEAD

Export repository as archive

git bundle create repo.bundle --all

Create repository bundle

git bundle unbundle repo.bundle

Unbundle repository

git notes add -m "note" <commit>

Add commit note

git filter-branch --force --index-filter

Rewrite history (use with caution)

git config --global core.ignorecase false

Case sensitive filenames

git config --global core.filemode false

Ignore file mode changes

git config --global push.default simple

Set default push mode

git config --global pull.rebase true

Default to rebase on pull

git config --global rerere.enabled true

Enable reuse recorded resolution

git check-ignore -v <file>

Check which rule ignores file

git ls-files

List tracked files

git ls-files --others --exclude-standard

List untracked files

git commit --fixup=<commit>

Create fixup commit

git commit --squash=<commit>

Create squash commit

git branch --set-upstream-to=origin/<branch>

Set upstream tracking

git branch --unset-upstream

Unset upstream tracking

git branch --edit-description

Edit branch description

git merge --no-commit --no-ff <branch>

Merge without committing

git merge-base <branch1> <branch2>

Find common ancestor

git push origin :<branch>

Delete remote branch (old syntax)

git push --set-upstream origin <branch>

Push and set upstream

git push --follow-tags

Push with following tags

git log --pretty=format:"%h %s" --graph

Custom format log

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

All branches graph log

git whatchanged

Show what changed per commit

git diff-tree --no-commit-id --name-only -r <commit>

Show commit changed files

git stash save "message"

Save stash (old syntax)

git stash create

Create stash without storing

git stash store <stash-hash>

Store specific hash as stash

git revert HEAD

Revert last commit

git revert HEAD~1..HEAD

Revert recent commit range

git update-index --assume-unchanged <file>

Assume file unchanged

git update-index --no-assume-unchanged <file>

Cancel assume unchanged

git update-index --skip-worktree <file>

Skip worktree check

git worktree add <path> <branch>

Add worktree

git worktree list

List worktrees

git worktree remove <path>

Remove worktree

git config --global core.autocrlf true

Auto handle line endings

git config --global color.ui auto

Enable colored output

git config --global merge.tool vimdiff

Set merge tool

git config --global diff.tool vimdiff

Set diff tool

git clone --mirror <url>

Clone mirror repository

git clone --single-branch <url>

Clone single branch only

git clone --branch <tag> <url>

Clone specific tag

git add --dry-run <file>

Dry run add operation

git add -f <file>

Force add ignored file

git rm --cached <file>

Remove from staging

git mv <old> <new>

Rename file

git commit --amend --no-edit

Amend without changing message

git commit --allow-empty

Allow empty commit

git commit --verbose

Show diff in commit message

git branch -vv

Show branch verbose info

git branch --contains <commit>

Find branches containing commit

git branch --no-merged

Show unmerged branches

git merge --abort

Abort merge

git merge --continue

Continue merge

git remote get-url origin

Get remote URL

git remote set-branches origin <branch>

Set tracking branches

git remote show origin

Show remote details

git log --since="2 weeks ago"

Commits since 2 weeks ago

git log --until="2024-01-01"

Commits until date

git log --author="name"

Filter by author

git log -S "string"

Search code changes

git log -p <file>

File history with diff

git tag -a <tag> -m "message"

Create annotated tag

git tag -d <tag>

Delete tag

git push origin --delete <tag>

Delete remote tag

git stash branch <branch>

Create branch from stash

git stash clear

Clear all stashes

git reset --soft HEAD~1

Soft reset last commit

git reset --mixed HEAD~1

Mixed reset (default)

git checkout -- <file>

Discard file changes

git submodule foreach <command>

Run command on all submodules

git submodule sync

Sync submodule URLs

git shortlog -sn

Commit summary by author

git describe --tags

Describe nearest tag

git cherry-pick --abort

Abort cherry-pick

git cherry-pick --continue

Continue cherry-pick

git bisect start

Start bisect

git bisect bad

Mark current as bad

git bisect good <commit>

Mark commit as good

git bisect reset

End bisect

194 of 194 commands shown

Related Tools

More Code & Dev Tools