Git Cheatsheet

Essential Git commands for daily work. Learn how to move fast, keep history clean, and recover safely.

When This Page Is Most Useful

This cheatsheet is most useful during everyday feature work, code review cleanup, and recovery after a mistaken reset, rebase, or merge. It focuses on commands developers actually reach for under pressure.

Create & Clone

Key / CodeDescription
git initInitialize a new repository.
git clone <url>Clone a remote repository.
git remote -vShow current remotes.
git remote add origin <url>Add a remote named origin.

Branching

Key / CodeDescription
git branchList local branches.
git branch -aList local and remote branches.
git checkout -b <name>Create and switch to a new branch.
git merge <branch>Merge a branch into the current branch.

Stage & Commit

Key / CodeDescription
git statusShow working tree status.
git add .Stage all changes.
git add -pStage changes interactively.
git commit -m "msg"Commit staged changes.

Inspect History

Key / CodeDescription
git log --oneline --graph --decorateCompact, visual history.
git diffShow unstaged changes.
git diff --stagedShow staged changes.
git show <commit>Show a specific commit.

Undo Safely

Key / CodeDescription
git restore <file>Discard unstaged changes in a file.
git reset HEAD <file>Unstage a file.
git revert <commit>Create a new commit that reverses a commit.
git reflogFind lost commits after reset or rebase.

Daily Flow

A clean daily workflow keeps history readable and reduces merge pain.

git checkout -b feature/login
# work...
git add -p
git commit -m "Add login form"

git pull --rebase origin main
# resolve conflicts if any
git push -u origin feature/login

Common Git Mistakes

The most expensive Git mistakes come from using destructive commands without checking status, branch, and remote state first. Before reset, rebase, or force push, confirm what is staged, what branch you are on, and whether commits already exist on a shared remote.

Related

Knowledge is power.