Git is the one tool every developer uses every day and most know only 20% of. Here are the commands and patterns that will actually save you.
# Rewrite the last 3 commits
git rebase -i HEAD~3
# Options in the interactive editor:
# pick — keep commit as-is
# reword — change commit message
# squash — merge into previous commit
# drop — delete commit entirely# Stash current work
git stash push -m "wip: navbar animation"
# List stashes
git stash list
# Apply and remove top stash
git stash pop
# Apply specific stash
git stash apply stash@{2}# Find which commit broke something
git bisect start
git bisect bad # Current commit is bad
git bisect good v1.0.0 # This commit was good
# Git checks out the midpoint commit
# Test it, then:
git bisect good # or: git bisect bad
# Git finds the exact commit that broke it
# When done:
git bisect reset# See everything that happened to HEAD
git reflog
# Recover after accidental reset
git reset --hard HEAD@{2} # Go back to where you were 2 moves ago# Apply a specific commit from another branch
git cherry-pick abc123def# Always rebase on pull (cleaner history)
git config --global pull.rebase true
# Better diff
git config --global diff.algorithm histogram
# Useful aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.lg "log --oneline --graph --decorate --all"Commit often, push often. The fancy commands exist for cleanup. The workflow that prevents disasters is small, frequent commits with clear messages.
git commit -m "fix" is not a message. It's a war crime against your future self.