The Git Commands Every Developer Should Actually Know
Forget memorising 150 git commands. These are the dozen that cover 95% of real work — plus the three that save you when things go wrong.

There are hundreds of git commands and you will never need most of them. After years of real work, the same dozen show up again and again. Learn these, understand the model behind them, and git stops being scary.
First, the mental model
Git has three places your code lives: the working directory (your actual files), the staging area (changes you've marked to save), and the repository (committed history). Almost every command moves changes between these three.

The daily dozen
git status # what's changed (run this constantly)
git add file.js # stage a file
git add . # stage everything
git commit -m "message" # save a snapshot
git pull # get + merge others' changes
git push # send your commits up
git branch feature-x # create a branch
git checkout feature-x # switch to it (or: git switch)
git merge feature-x # bring a branch's work in
git log --oneline # readable history
git diff # what exactly changed
git clone url # copy a repo locally
That's the 95%. Notice how much is just status → add → commit → push. Master that loop and you're productive.
Run git status obsessively. It's the command that prevents the mistakes the other commands have to clean up.
The three that save you
Things go wrong; these get you out:
git restore file.js— throw away uncommitted changes to a file.git reset --soft HEAD~1— undo the last commit but keep the work.git stash— shelve changes to switch tasks, thengit stash popto bring them back.
And the safety net of safety nets: git reflog. It records almost every move you make, so even a "lost" commit is usually recoverable. Knowing reflog exists is what lets you experiment without fear.
Commit like someone will read it
Write commit messages in the imperative ("Add login validation," not "added stuff"). Keep commits small and focused. Your future self — and the AI tools that now summarise diffs — will thank you. If you're pairing with an AI coding assistant, clean commits make its job dramatically easier too.
Key takeaways
- Git moves changes between working dir, staging, and repository.
- The status → add → commit → push loop covers most work.
- restore, reset --soft and stash get you out of trouble.
- reflog is your undo-of-last-resort — experiment freely.
Frequently asked questions
What's the difference between git fetch and git pull?
fetch downloads new commits but doesn't change your files. pull does a fetch and then merges them into your branch. Fetch first if you want to look before you leap.
How do I undo my last commit?
git reset --soft HEAD~1 undoes the commit but keeps your changes staged. Use --mixed (the default) to unstage them too. Avoid --hard unless you truly want the changes gone.