15 Git Tricks That Will Save You Hours Every Week in 2026

15 Git Tricks That Will Save You Hours Every Week in 2026

DevForge

Every developer uses Git daily, but most only know the basics. Here are 15 lesser-known Git tricks that senior developers use to save hours every week.

1. Undo Your Last Commit (Keep Changes)

git reset --soft HEAD~1

This undoes the commit but keeps your changes staged. Perfect when you committed too early.

2. See What Changed in a Specific Commit

git show abc1234 --stat

The --stat flag gives a clean summary of files changed, lines added/removed.

3. Find Who Wrote a Specific Line

git blame -L 10,20 file.js

Blame a specific line range instead of the whole file. Add -w to ignore whitespace changes.

4. Stash Only Specific Files

git stash push -m "WIP feature" -- src/feature.js src/utils.js

Selective stashing is a game-changer when you are working on multiple things.

5. Interactive Rebase to Clean History

git rebase -i HEAD~5

Squash, reorder, or edit your last 5 commits before pushing. Clean commit history = happy reviewers.

6. Find When a Bug Was Introduced

git bisect start
git bisect bad
git bisect good v1.0.0

Git bisect does a binary search through your commits to find exactly which commit introduced a bug.

7. Create Aliases for Common Commands

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"

Type git co instead of git checkout. Type git lg for a beautiful graph log.

8. Search Code Across All Commits

git log -S "functionName" --all

The -S flag (pickaxe) searches for when a string was added or removed across your entire history.

9. Recover a Deleted Branch

git reflog
git checkout -b recovered-branch abc1234

The reflog keeps 90 days of history. Nothing is truly lost in Git.

10. Cherry-Pick a Commit from Another Branch

git cherry-pick abc1234

Apply a single commit from any branch without merging the whole branch.

11. See File at a Previous Version

git show HEAD~3:src/app.js

View any file as it was at any point in history, without checking out that commit.

12. Auto-Fix Whitespace Issues

git diff --check

Catches trailing whitespace and mixed indentation before your CI does.

13. Create a Patch File

git diff > my-changes.patch
git apply my-changes.patch

Share changes with someone without pushing to a remote repository.

14. Worktrees for Parallel Development

git worktree add ../hotfix-branch hotfix/urgent

Work on two branches simultaneously without stashing. Each worktree is a separate directory.

15. Clean Up Merged Branches

git branch --merged main | grep -v main | xargs git branch -d

One-liner to delete all local branches that have been merged into main.

Want All Developer Cheatsheets in One Place?

The Developer Cheatsheet Bundle ($9) includes Git, Bash, Docker, Kubernetes, regex, and more — all formatted for quick reference.

Get it here: http://69.62.106.38:3104/product/developer-cheatsheet-bundle

Free Developer Tools

Try 18 free API endpoints (no signup): curl http://69.62.106.38:3100/api/hash/sha256?text=hello

Test webhooks free: http://69.62.106.38:3101

Free JSON tools: http://69.62.106.38:3107

All free tools: http://69.62.106.38:3103

Report Page