- Published on
Git Tips Every Developer Should Know - Beyond the Basics
- Authors

- Name
- Sanjeev Sharma
- @webcoderspeed1
Introduction
Most developers use about 10% of Git's capabilities — add, commit, push, pull. But mastering Git's advanced features can save you hours every week and make you a dramatically better collaborator.
Here are the tips that will level up your Git game immediately.
- 1. Interactive Rebase — Rewrite History Cleanly
- 2. git stash — Save Work Without Committing
- 3. git bisect — Find the Commit that Broke Everything
- 4. git reflog — Undo Anything
- 5. Useful git log Formats
- 6. git cherry-pick — Apply Specific Commits
- 7. Git Aliases — Stop Typing Long Commands
- 8. git diff Tips
- 9. Undoing Things
- 10. .gitignore Tips
- Conclusion
1. Interactive Rebase — Rewrite History Cleanly
Interactive rebase lets you edit, squash, reorder, and split commits before pushing:
# Rebase the last 5 commits interactively
git rebase -i HEAD~5
You'll see an editor with options for each commit:
pick abc1234 Add user model
pick def5678 Fix typo in user model
pick ghi9012 Add user controller
pick jkl3456 WIP: user service
pick mno7890 Finish user service
# Commands:
# p, pick = use commit
# r, reword = use commit but edit message
# s, squash = squash into previous commit
# f, fixup = squash but discard message
# d, drop = remove commit
Change pick to squash to combine messy WIP commits into one clean commit before pushing.
2. git stash — Save Work Without Committing
# Stash your current changes
git stash
# Stash with a description
git stash push -m "WIP: user auth feature"
# List all stashes
git stash list
# stash@{0}: On main: WIP: user auth feature
# stash@{1}: On main: Quick fix attempt
# Apply and remove the latest stash
git stash pop
# Apply a specific stash (without removing it)
git stash apply stash@{1}
# Stash only specific files
git stash push -m "api changes" src/api/users.ts
# Delete all stashes
git stash clear
3. git bisect — Find the Commit that Broke Everything
# Start bisect session
git bisect start
# Mark current commit as bad
git bisect bad
# Mark a known good commit
git bisect good v1.2.0
# Git will checkout the middle commit — test it
# If it's bad:
git bisect bad
# If it's good:
git bisect good
# Git automatically narrows down — binary search!
# Eventually tells you exactly which commit introduced the bug
# Reset when done
git bisect reset
This finds the exact breaking commit in O(log n) steps — a 1000-commit history takes just 10 steps!
4. git reflog — Undo Anything
reflog is your safety net. It records every position HEAD has been at:
git reflog
# HEAD@{0}: commit: Add new feature
# HEAD@{1}: reset: moving to HEAD~1
# HEAD@{2}: commit: Oops, bad commit
# HEAD@{3}: checkout: moving from feature to main
# Recover a "lost" commit
git checkout HEAD@{2}
# Recover after an accidental reset --hard
git reset --hard HEAD@{3}
Almost nothing in Git is truly lost if you act within 90 days (the reflog expiry).
5. Useful git log Formats
# Beautiful one-line log
git log --oneline --graph --all --decorate
# Show commits with file diffs
git log -p
# Show commits that changed a specific file
git log --follow -p src/components/Button.tsx
# Show commits between two dates
git log --after="2026-01-01" --before="2026-03-01"
# Show commits by author
git log --author="Alice"
# Search commits by message
git log --grep="fix auth"
# My favorite alias
git log --oneline --graph --decorate --all
6. git cherry-pick — Apply Specific Commits
# Apply a specific commit from another branch to current branch
git cherry-pick abc1234
# Cherry-pick a range of commits
git cherry-pick abc1234..def5678
# Cherry-pick without committing (just apply changes)
git cherry-pick --no-commit abc1234
Useful when you've fixed a bug on main and need that exact fix on a release branch too.
7. Git Aliases — Stop Typing Long Commands
Add these to your ~/.gitconfig:
[alias]
st = status
co = checkout
br = branch
ci = commit
lg = log --oneline --graph --decorate --all
undo = reset HEAD~1 --mixed
unstage = reset HEAD --
last = log -1 HEAD
wip = commit -am "WIP"
unwip = reset HEAD~1 --mixed
aliases = config --get-regexp alias
Now you can just type git lg or git undo.
8. git diff Tips
# See what you're about to commit
git diff --staged
# Compare two branches
git diff main..feature-branch
# Compare specific files between branches
git diff main feature-branch -- src/api/users.ts
# Show only file names that changed
git diff --name-only main..HEAD
# Word-level diff (easier to read)
git diff --word-diff
9. Undoing Things
# Undo last commit but keep changes staged
git reset HEAD~1 --soft
# Undo last commit and unstage changes
git reset HEAD~1 --mixed
# Undo last commit AND discard changes (dangerous!)
git reset HEAD~1 --hard
# Undo a specific commit by creating a new commit
git revert abc1234 # Safe for shared branches
# Unstage a file
git restore --staged file.txt
# Discard local changes to a file
git restore file.txt
10. .gitignore Tips
# Create a .gitignore based on your project type
# Visit gitignore.io or use GitHub's templates
# See what's being ignored
git check-ignore -v filename
# Force add an ignored file
git add -f file.txt
# Remove a file from tracking (but keep it locally)
git rm --cached sensitive-file.txt
Conclusion
Git is one of those tools where learning 10 extra commands saves you 10 hours a week. Master rebase -i for clean commits, stash for context switching, bisect for debugging, and reflog as your safety net. These habits separate senior engineers from everyone else.