xutil.dev
Login

Git Cheatsheet

Quick reference for Git commands covering basics, branching, remote operations, stash, log, rebase, tagging, and configuration

79 commands

git init

Initialize a new Git repository

git clone

Clone a remote repository

git clone --depth

Create a shallow clone

git add

Add files to staging area

git add -A

Add all changes to staging

git add -p

Stage changes interactively

git commit

Commit staged changes

git commit --amend

Amend last commit

git status

Show working tree status

git rm

Remove file and stage deletion

git rm --cached

Untrack file without deleting

git mv

Move or rename a file

git branch

List local branches

git branch -a

List all branches including remote

git branch (create)

Create a new branch

git branch -d

Delete merged branch

git branch -D

Force delete branch

git branch -m

Rename a branch

git checkout

Switch to a branch

git checkout -b

Create and switch to branch

git switch

Switch branch (modern command)

git switch -c

Create and switch branch (modern)

git remote -v

List remote repositories

git remote add

Add a remote repository

git remote remove

Remove a remote repository

git remote rename

Rename a remote repository

git fetch

Fetch changes without merge

git fetch --prune

Prune deleted remote branches

git pull

Fetch and merge remote changes

git pull --rebase

Pull with rebase

git push

Push local changes to remote

git push -u

Push and set upstream branch

git push --force-with-lease

Safe force push

git stash

Stash current changes

git stash -m

Stash with message

git stash list

List all stashes

git stash pop

Apply and remove latest stash

git stash apply

Apply stash without removing

git stash drop

Drop a stash

git stash clear

Clear all stashes

git stash show

Show stash changes

git stash branch

Create branch from stash

git log

Show commit history

git log --oneline

Show compact commit history

git log --graph

Show log with branch graph

git log -p

Show log with diffs

git log --author

Show commits by author

git log --since

Show commits since date

git diff

Show unstaged changes

git diff --staged

Show staged changes

git diff branch1..branch2

Show diff between branches

git blame

Show who changed each line

git shortlog

Show commit summary by author

git merge

Merge a branch

git merge --no-ff

Merge without fast-forward

git merge --squash

Squash merge

git rebase

Rebase current branch

git rebase --abort

Abort rebase

git rebase --continue

Continue rebase after conflict

git cherry-pick

Apply specific commit

git revert

Create commit that reverts changes

git reset --soft

Undo commit keeping changes staged

git reset --mixed

Undo commit keeping changes unstaged

git tag

List all tags

git tag (lightweight)

Create lightweight tag

git tag -a

Create annotated tag

git tag -d

Delete local tag

git push origin --tags

Push all tags to remote

git push origin --delete tag

Delete remote tag

git show tag

Show tag details

git config --global user.name

Set global user name

git config --global user.email

Set global email

git config --list

List all config settings

git config --global core.editor

Set default editor

git clean -fd

Remove untracked files

git clean -n

Dry run to see files to clean

git bisect start

Start binary search for bug

git reflog

Show reference log

git worktree add

Add a working tree