Git Cheatsheet

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

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
Knowledge is power.