Git Cheat Sheet: Essential Quick Reference Guide
Today I compiled a Git Cheat Sheet for quick recall of all the commands I’ve been practicing. Instead of memorizing, I wanted a single document where I can find the most common workflows, along with short explanations and examples.
1. Git Configuration
Before starting, always configure Git with your details:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --list
This ensures commits are linked to your identity.
2. Git Basics (Workflow)
Git follows a 3-step workflow: Working Directory → Staging Area → Local Repository
Check status →
git statusAdd file →
git add file.txtAdd all →
git add .Commit →
git commit -m "Message"
Note: Files cannot skip staging when moving to local repo.
3. File Recovery
Restore deleted (not staged) →
git restore file.txtRestore staged →
git restore --staged file.txt && git restore file.txtRestore after commit →
git checkout HEAD~1 -- file.txt
4. Git Stash
When you want to save uncommitted work without committing:
git stash
git stash list
git stash apply
git stash drop stash@{id}
git stash clear
5. Remote Repositories
Clone repo →
git clone <repo-url>Add remote →
git remote add origin <repo-url>Push changes →
git push -u origin mainPull changes →
git pull origin mainFetch changes →
git fetch
6. Branching
List →
git branchCreate →
git branch feature-1Switch →
git checkout feature-1Create + Switch →
git checkout -b feature-1Rename →
git branch -m oldName newNameDelete local →
git branch -D feature-1Delete remote →
git push origin --delete feature-1
7. Merge & Rebase
Merging keeps full history; rebasing creates a linear history.
Merge Example:
git checkout main
git merge feature-1
Rebase Example:
git checkout feature-1
git rebase main
8. Merge Conflicts
When conflicts occur:
Open file → resolve between
<<<<<<<and>>>>>>>.Stage →
git add file.txtCommit →
git commit -m "Resolved conflict"
9. .gitignore
Used to exclude files from version control. Example:
*.log
node_modules/
.env
10. GitHub Workflow
Steps to push local code to a new GitHub repo:
git init
git add .
git commit -m "Initial commit"
git remote add origin <repo-url>
git push -u origin main
11. Forking & Pull Requests
Fork repo on GitHub.
Clone forked repo locally.
Push changes to fork.
Raise a Pull Request (PR) to the original repository.
12. Useful Commands
Commit history →
git log --oneline --graph --decorateShow last commit →
git show HEADUndo last commit (keep changes) →
git reset --soft HEAD~1Undo last commit (discard changes) →
git reset --hard HEAD~1Remove untracked files →
git clean -f
Closing Notes
This cheat sheet helps me quickly recall Git commands while working on projects. Git is powerful but can get overwhelming — keeping these short references handy makes it much easier to focus on actual coding and version control.