Git Cheatsheet — Common Commands Quick Reference
Git Cheatsheet — Common Commands Quick Reference
DodaTech
3 min read
Git commands for setup, staging, branching, merging, remote operations, history inspection, and undo — the essential toolkit for version control.
Setup & Configuration
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch mainBasic Workflow
| Command | What it does |
|---|---|
git init | Initialize repo in current dir |
git clone <url> | Copy remote repo locally |
git add <file> | Stage changes |
git add . | Stage all changes |
git commit -m "msg" | Commit staged changes |
git status | Show working tree state |
git log --oneline | Compact commit history |
Branching & Merging
git branch <name> # create branch
git checkout <name> # switch branch
git switch <name> # modern alternative
git checkout -b <name> # create + switch
git merge <branch> # merge into current
git branch -d <name> # delete branchRemote Operations
| Command | What it does |
|---|---|
git remote -v | List remotes |
git remote add origin <url> | Add remote |
git push origin main | Push to remote |
git pull origin main | Fetch + merge |
git fetch origin | Fetch without merge |
Undoing Changes
git restore <file> # discard unstaged changes
git restore --staged <f> # unstage (keep changes)
git reset HEAD~1 # undo last commit (keep changes)
git reset --hard HEAD~1 # undo + discard changes
git revert <hash> # safe undo via new commitStash
git stash # save work-in-progress
git stash pop # restore + remove stash
git stash list # list stashes
git stash drop # remove top stashDiff & Log
git diff # unstaged changes
git diff --staged # staged changes
git log --oneline -5 # last 5 commits
git log --graph --all # visual branch graph
git blame <file> # who changed whatTag
git tag v1.0.0 # lightweight tag
git tag -a v1.0.0 -m "msg" # annotated tag
git push origin --tags # push all tags.gitignore
# Common entries
node_modules/
.env
*.log
dist/
.DS_StoreCommon Workflows
Feature branch:
git checkout -b feature-x
git add . && git commit -m "Add feature x"
git checkout main && git merge feature-xFix last commit:
git add forgotten-file.js
git commit --amend --no-editSee the complete Git tutorials for advanced workflows.
Previous
JavaScript Cheatsheet — Complete Quick Reference
Next
Docker Cheatsheet — Commands & Quick Reference
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro