Most developers know add, commit, push. Here are the Git commands and workflows that separate juniors from seniors.
Interactive Rebase: Clean Up Your History
# Squash last 3 commits into one
git rebase -i HEAD~3
Your editor opens:
pick abc1234 Add user model
pick def5678 Fix typo in user model
pick ghi9012 Add validation to user model
Change to:
pick abc1234 Add user model
squash def5678 Fix typo in user model
squash ghi9012 Add validation to user model
Result: one clean commit instead of three messy ones.
Stash: Save Work Without Committing
# Save current changes
git stash
# Save with a description
git stash push -m "WIP: user authentication"
# List stashes
git stash list
# Apply most recent stash
git stash pop
# Apply specific stash
git stash apply stash@{2}
# Stash only specific files
git stash push -m "partial work" src/auth.py src/models.py
Bisect: Find the Bug-Introducing Commit
git bisect start
git bisect bad # current commit is broken
git bisect good v1.0.0 # this tag was working
# Git checks out a middle commit. Test it, then:
git bisect good # if this commit works
git bisect bad # if this commit is broken
# Git narrows down to the exact commit that introduced the bug
# When done:
git bisect reset
Automate it:
git bisect start HEAD v1.0.0
git bisect run python -m pytest tests/test_auth.py
Cherry-Pick: Grab Specific Commits
# Apply a specific commit from another branch
git cherry-pick abc1234
# Cherry-pick without committing (stage changes only)
git cherry-pick --no-commit abc1234
# Cherry-pick a range
git cherry-pick abc1234..def5678
Reflog: Your Safety Net
# See everything you've done (even "deleted" commits)
git reflog
# Recover a "lost" commit after a bad reset
git reset --hard HEAD@{3}
# Recover a deleted branch
git checkout -b recovered-branch HEAD@{5}
Worktrees: Multiple Branches Simultaneously
# Work on a hotfix without switching branches
git worktree add ../hotfix-branch hotfix/critical-bug
# Now you have two directories, each on a different branch
cd ../hotfix-branch
# fix the bug, commit, push
cd ../main-repo
# Clean up
git worktree remove ../hotfix-branch
Better Diffs and Logs
# Word-level diff (great for prose/docs)
git diff --word-diff
# Show changes in a specific function
git log -p -L :function_name:file.py
# Pretty log with graph
git log --oneline --graph --all --decorate
# Find who changed a line
git blame -L 10,20 src/auth.py
# Search commit messages
git log --grep="fix auth"
# Search code changes
git log -S "def authenticate" --oneline
Aliases for Speed
# Add to ~/.gitconfig
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st "status -sb"
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.undo "reset --soft HEAD~1"
git config --global alias.amend "commit --amend --no-edit"
Commit Message Convention
# Format: type(scope): description
git commit -m "feat(auth): add JWT refresh token support"
git commit -m "fix(api): handle null response from payment gateway"
git commit -m "docs(readme): update installation instructions"
git commit -m "refactor(db): extract query builder into separate module"
# Types: feat, fix, docs, style, refactor, test, chore
Key Takeaways
- Interactive rebase keeps your history clean and reviewable
- Bisect finds bug-introducing commits automatically
- Reflog is your safety net — almost nothing is truly lost in Git
- Worktrees let you work on multiple branches without stashing
- Good commit messages make debugging and reviewing much easier
6. Aliases save hundreds of keystrokes per day
🚀 Level up your AI workflow! Check out my AI Developer Mega Prompt Pack — 80 battle-tested prompts for developers. $9.99
Top comments (0)