Git Cheatsheet
Essential Git commands for daily work. Learn how to move fast, keep history clean, and recover safely.
Create & Clone
| Key / Code | Description |
|---|---|
| git init | Initialize a new repository. |
| git clone <url> | Clone a remote repository. |
| git remote -v | Show current remotes. |
| git remote add origin <url> | Add a remote named origin. |
Branching
| Key / Code | Description |
|---|---|
| git branch | List local branches. |
| git branch -a | List 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 / Code | Description |
|---|---|
| git status | Show working tree status. |
| git add . | Stage all changes. |
| git add -p | Stage changes interactively. |
| git commit -m "msg" | Commit staged changes. |
Inspect History
| Key / Code | Description |
|---|---|
| git log --oneline --graph --decorate | Compact, visual history. |
| git diff | Show unstaged changes. |
| git diff --staged | Show staged changes. |
| git show <commit> | Show a specific commit. |
Undo Safely
| Key / Code | Description |
|---|---|
| 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 reflog | Find 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/loginKnowledge is power.