๐ Git Cheatsheet
Quick reference for everyday Git commands ยท gitlearn.mohitm.github.io
๐ง Setup
| git config user.name "Name" | Set your name |
| git config user.email "e@mail" | Set your email |
| git init | Init a new repo |
| git clone <url> | Clone a remote repo |
๐ธ Staging & Committing
| git status | Show working tree status |
| git add <file> | Stage a file |
| git add . | Stage all changes |
| git commit -m "msg" | Commit with message |
| git commit --amend | Edit last commit |
๐ฟ Branching
| git branch | List branches |
| git branch <name> | Create branch |
| git checkout <name> | Switch branch |
| git checkout -b <name> | Create & switch |
| git branch -d <name> | Delete branch |
๐ Merging & Rebasing
| git merge <branch> | Merge into current |
| git rebase <branch> | Rebase onto branch |
| git rebase -i HEAD~n | Interactive rebase |
| git cherry-pick <id> | Apply a commit |
๐ Remote
| git remote add origin <url> | Add remote |
| git push origin <branch> | Push branch |
| git pull | Fetch & merge |
| git fetch | Fetch only |
| git push -u origin main | Push & track |
๐ Inspect & Undo
| git log --oneline | Compact history |
| git diff | Show unstaged diff |
| git stash | Stash changes |
| git stash pop | Restore stash |
| git reset --hard HEAD | Discard all changes |