5 Git Commands Every Developer Should Know
Git is one of the most important tools every developer uses, yet many people only know a few basic commands.
Learning a handful of additional Git commands can save time, reduce mistakes, and make collaboration much easier.
Here are five Git commands I use almost every day.
1. Check What Changed
Before committing anything, always check your changes.
git status
This command shows:
- Modified files
- New files
- Deleted files
- Files ready to commit
Running git status before every commit is a good habit.
2. View Your Commit History
Need to know what happened recently?
git log --oneline
Instead of showing long commit details, this command displays a clean, compact history.
Example:
f82d4f1 Fix login bug
1ab8c72 Update README
8ce44f0 Add authentication
It's much easier to read than the default output.
3. Create a New Branch
Never work directly on the main branch.
Create a feature branch instead.
git checkout -b feature/login
Or, with newer Git versions:
git switch -c feature/login
This keeps your work isolated until it's ready to merge.
4. Undo Staged Changes
Accidentally added the wrong file?
git restore --staged filename.js
This removes the file from the staging area without deleting your changes.
It's much safer than trying to fix mistakes later.
5. Pull Before You Push
Before pushing your code, make sure your local branch is up to date.
git pull origin main
This helps avoid unnecessary merge conflicts and ensures you're working with the latest code.
Bonus Tip
If you forget a command, Git has built-in help.
git help <command>
For example:
git help commit
The documentation is surprisingly helpful.
Final Thoughts
You don't need to memorize every Git command.
Mastering a small set of frequently used commands will make your daily workflow smoother and reduce common mistakes.
The five commands I recommend every beginner learns are:
git statusgit log --onelinegit switch -cgit restore --stagedgit pull
Once you're comfortable with these, learning more advanced Git features becomes much easier.
Which Git command do you use the most? Let me know in the comments!
Top comments (1)
Great list! I’d also add git diff (and git diff --staged). Before every commit, I like to review exactly what changed—not just which files changed. It’s a simple habit that catches accidental edits and saves a surprising number of “oops” commits.