🔀 Git Commands Cheat Sheet
Complete Git reference — from basic setup to advanced workflows. Commands, options, and real-world examples.
Advertisement
📖 Common Git Workflows
# Start a new feature
git checkout -b feature/new-feature
# Work on your code, then stage and commit
git add .
git commit -m "feat: add new feature"
# Push to remote and create PR
git push -u origin feature/new-feature
# After PR is merged, clean up
git checkout main
git pull origin main
git branch -d feature/new-feature
# Undo last commit (keep changes)
git reset --soft HEAD~1
# Undo last commit (discard changes)
git reset --hard HEAD~1
# Amend last commit message
git commit --amend -m "new message"
❓ Frequently Asked Questions
git merge creates a new merge commit that combines two branches. It preserves full history but can create a cluttered log. git rebase replays your commits on top of another branch, creating a linear history. Use merge for public/shared branches and rebase for local feature branches before merging.
Use git revert <commit-hash> to create a new commit that undoes the changes (safe for shared branches). Avoid git reset --hard + force push on shared branches as it rewrites history and can break other developers' work.