We all use git daily, but it has a ton of powerful (and lesser-known) features that can make your life easier. Here are some Git tricks that go beyond git status and git push.
- Undo Your Last Commit (But Keep Changes)
git reset --soft HEAD~1
This undoes your last commit but keeps your changes staged. Super handy when you realize your commit message was wrong or you forgot to include a file.
-
Undo Last Commit (keep changes)
- Remove a File from History (Without Nuking Your Repo)
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch SECRET_FILE" \
--prune-empty --tag-name-filter cat -- --all
Oops! Did you commit an API key? This will remove the file from all commits.
(Use with caution — history rewrite ahead!)
-
Remove a File from Git History
📘 Removing Sensitive Data from Git History
- See Who Changed a Specific Line
git blame FILE
Find out who changed which line of code and when. Useful for tracking down bugs or understanding legacy logic.
-
Git Blame
📘 Git Blame Documentation
- Stash Only Certain Files
git stash push -m "my partial stash" myfile.js
No need to stash everything. This command lets you stash just one or a few files.
-
Stash Specific Files
- Show Changes in a File You Staged
git diff --cached
Check what's going to be committed — super helpful before running git commit.
-
Show Staged Changes
- Remove Local Branches That Are Already Merged
git branch --merged | grep -v '*' | xargs git branch -d
Clean up your local repo by deleting all fully merged branches.
-
Remove Merged Branches
- See Your Commit History Like a Tree
git log --oneline --graph --all
Visualize your commit history across branches. Great for understanding project flow.
-
View Commit Tree
💬 Got Any Favorites?
Which of these did you not know? Or do you have a secret Git trick of your own?
Drop it below — let’s learn from each other! 🙌