Dev.to WebDev 🛠 Dev 👁 1 📖 2 min read

15 Git Commands That Save Me Hours Every Week (And Why Most Developers Don't Know Them)

Most developers use 10 Git commands and Google the rest. That wastes 15+ minutes every day searching for the right syntax. After 8 years of daily Git usage, here are the 15 commands that actually save me hours every wee

Most developers use 10 Git commands and Google the rest. That wastes 15+ minutes every day searching for the right syntax.

After 8 years of daily Git usage, here are the 15 commands that actually save me hours every week — organized by the problem they solve.

Daily Workflow (5 commands)

1. git switch -c <branch> — Create and switch in one step

git switch -c feature/payment-refactor

Replaces git checkout -b. Cleaner, explicit intent. Added in Git 2.23.

2. git restore --staged <file> — Unstage without losing changes

git restore --staged package-lock.json

Replaces git reset HEAD <file>. Your working directory stays intact.

3. git switch - — Jump back to previous branch

git switch feature/auth
# ... work ...
git switch -  # back to main

Instant context switching. No need to remember branch names.

4. git commit -v — See diff in your editor while committing

git commit -v

Shows the full diff in your commit message buffer. Catches stray console.log before they ship.

5. git log --oneline --graph --all -20 — Visual history at a glance

git log --oneline --graph --all -20

Alias this. You'll use it 20x/day.

Fixing Mistakes (5 commands)

6. git commit --amend --no-edit — Fix the last commit silently

git add forgotten-file.js
git commit --amend --no-edit

Adds staged changes to previous commit without opening editor.

7. git reset --soft HEAD~1 — Undo commit, keep changes staged

git reset --soft HEAD~1
# changes still staged, ready to re-commit properly

Perfect for splitting one messy commit into two clean ones.

8. git restore <file> — Discard working directory changes

git restore broken-experiment.js

Replaces git checkout -- <file>. Safer — won't switch branches by accident.

9. git reflog — The time machine

git reflog
# find the hash you want
git reset --hard <hash>

Recovers "lost" commits, reset mistakes, rebase gone wrong. Never truly loses data.

10. git bisect — Find the bug-introducing commit automatically

git bisect start
git bisect bad HEAD
git bisect good v2.0.0
# Git checks out middle commit — test, mark good/bad, repeat
git bisect reset

Binary search through history. Finds the exact commit that broke something in log₂(n) steps.

Branch Management (5 commands)

11. git branch --merged / --no-merged — Clean up merged branches

git branch --merged | grep -v main | xargs git branch -d
git branch --no-merged  # shows work-in-progress

Safe cleanup. --merged only deletes fully merged branches.

12. git worktree add ../hotfix main — Parallel work without stashing

git worktree add ../hotfix main
cd ../hotfix
# fix critical bug on main
cd ../main
git worktree remove ../hotfix

Multiple working directories from one repo. No stash/unstash dance.

13. git push --force-with-lease — Safe force push

git push --force-with-lease origin feature/auth

Fails if someone else pushed to the branch. Prevents overwriting teammates' work.

14. git fetch --prune — Clean up dead remote refs

git fetch --prune

Removes local tracking branches for deleted remote branches. Run weekly.

15. git maintenance start — Background repo optimization

git maintenance start

Runs gc, commit-graph, prefetch in background. Keeps large repos fast automatically.

More Developer Resources

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.