12 Git Commands Every Developer Should Know (With Practical Examples)
Whether you're working on a solo side project or collaborating with a large engineering team, Git is one of the most important tools in a developer's toolkit.
Many developers know just enough Git to get by—git add, git commit, and git push. But learning a few additional commands can save hours of debugging, prevent mistakes, and make collaboration much smoother.
In this article, we'll walk through 12 Git commands that every developer should understand, complete with practical examples and common use cases.
1. Check the Status of Your Repository
git status
This command shows:
- Modified files
- New files
- Deleted files
- Files staged for commit
- Current branch
Example:
On branch feature/login
Changes not staged for commit:
modified: src/app.ts
Untracked files:
README.md
This is often the first command you should run before committing changes.
2. Stage Files
Stage a single file:
git add app.js
Stage everything:
git add .
Only staged files become part of your next commit.
3. Commit Changes
git commit -m "Add user authentication"
A good commit message explains what changed, not just that something changed.
Good examples:
✅ Fix login validation
✅ Add pagination to Products API
❌ Changes
❌ Update
4. View Commit History
git log
For a cleaner view:
git log --oneline
Example:
d91a31c Fix JWT validation
94ab621 Add user profile endpoint
c2f70f1 Initial project setup
5. Create a New Branch
git checkout -b feature/payment
Or using the newer command:
git switch -c feature/payment
Creating feature branches keeps your main branch stable.
6. Switch Between Branches
git switch main
or
git checkout main
Always verify you're on the correct branch before making changes.
7. Pull Latest Changes
git pull origin main
This downloads and merges the latest commits from the remote repository.
Pull regularly to reduce merge conflicts.
8. Push Your Changes
git push origin feature/payment
Your teammates can't review your work until it's pushed.
9. See What Changed
git diff
Compare staged changes:
git diff --staged
This is extremely useful before committing.
10. Undo the Last Commit (Without Losing Changes)
If you committed too early:
git reset --soft HEAD~1
Your changes remain staged, allowing you to edit and recommit.
11. Stash Temporary Work
Need to switch branches without committing unfinished work?
git stash
Restore it later:
git stash pop
Git Stash is perfect when an urgent production issue interrupts your current task.
12. View Remote Repositories
git remote -v
Example:
origin https://github.com/company/project.git
Useful when working with multiple remotes or verifying repository URLs.
Bonus Tips
Here are a few habits that can improve your Git workflow:
- Commit small, focused changes.
- Pull before pushing.
- Write meaningful commit messages.
- Avoid committing generated files unless necessary.
- Review changes with
git diffbefore every commit. - Use feature branches instead of committing directly to
main. - Resolve merge conflicts carefully instead of rushing through them.
A Typical Git Workflow
git pull origin main
git checkout -b feature/profile
git add .
git commit -m "Add profile page"
git push origin feature/profile
Then create a Pull Request for code review.
This workflow keeps collaboration organized and makes changes easier to review.
Final Thoughts
Git is much more than a version control system—it's a collaboration tool that helps teams build software safely and efficiently.
You don't need to memorize every Git command, but mastering the essentials can make your daily development workflow faster, reduce mistakes, and give you more confidence when working on real-world projects.
Which Git command do you use the most? Are there any lesser-known Git tricks that have saved you time? Share them in the comments—I’m always looking to learn new workflows from the community.
🚀 Explore More Free Developer Tools
If you regularly work with JSON, APIs, encoding, formatting, validation, or debugging, you might find ToolBenchApp useful:
ToolBenchApp is a growing collection of free browser-based developer tools designed to simplify everyday development tasks. Whether you need to format JSON, decode JWTs, compare text, generate UUIDs, or convert data between formats, the goal is to help developers stay productive without leaving the browser.
I'm continuously improving the platform based on developer feedback, so if there's a tool you'd like to see added, I'd love to hear your suggestions.
Top comments (0)