Back to all threads
programmingCommunity threadOctober 24, 2026

15 Git Commands Every Developer Should Know (Beyond add, commit, push)

Stop googling the same Git problems. Learn the commands that undo mistakes, clean up history, and save you hours every week.

15 Git Commands Every Developer Should Know (Beyond add, commit, push)

Why most developers only use 10% of Git

Most of us learn git add, git commit, and git push, then copy-paste Stack Overflow answers whenever something breaks. This guide covers the commands that actually get you out of trouble, and that you'll use again and again.

1. Undo the last commit (keep your changes)

git reset --soft HEAD~1

You committed too early. This removes the commit but keeps your code staged.

2. Undo the last commit (throw changes away)

git reset --hard HEAD~1

Use carefully. This permanently discards your work.

3. Fix the last commit message

git commit --amend -m "Better message"

4. Save work without committing

git stash
git stash pop

Perfect when you need to switch branches quickly.

5. See what changed

git diff
git diff --staged

6. View a clean history

git log --oneline --graph --all

7. Switch branches (modern way)

git switch main
git switch -c new-feature

8. Restore a file you broke

git restore filename.js

9. Delete a branch

git branch -d old-branch

10. Find who changed a line

git blame filename.js

11. Find the commit that broke things

git bisect start

Git does a binary search through your history to find the bad commit.

12. Recover "lost" commits

git reflog

Almost nothing in Git is truly lost. reflog shows everything you've done recently.

13. Copy one commit to another branch

git cherry-pick <commit-hash>

14. Clean up untracked files

git clean -fd

15. Rebase instead of merge for a cleaner history

git rebase main

Quick cheat sheet

| Problem | Command | |---|---| | Wrong commit message | git commit --amend | | Need to switch branch fast | git stash | | Lost a commit | git reflog | | Broke a file | git restore <file> | | Find a bug's origin | git bisect |

Final thoughts

You don't need to memorize all 15. Bookmark this page, learn two or three a week, and Git will stop being scary. Which command saved you the most time? Tell me in the comments.

G

Written by

gamerskeleton115

ML/AI engineer and tech writer covering artificial intelligence, machine learning, software development, and the technology shaping our world. Passionate about making complex technical concepts accessible to everyone.

Last updated: October 24, 2026More about the author
15 Git Commands Every Developer Should Know (Beyond add, commit, push) - DevThread