DEV Community

ToolBench
ToolBench

Posted on

12 Git Commands Every Developer Should Know (With Practical Examples)

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

This is often the first command you should run before committing changes.


2. Stage Files

Stage a single file:

git add app.js
Enter fullscreen mode Exit fullscreen mode

Stage everything:

git add .
Enter fullscreen mode Exit fullscreen mode

Only staged files become part of your next commit.


3. Commit Changes

git commit -m "Add user authentication"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

For a cleaner view:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Example:

d91a31c Fix JWT validation
94ab621 Add user profile endpoint
c2f70f1 Initial project setup
Enter fullscreen mode Exit fullscreen mode

5. Create a New Branch

git checkout -b feature/payment
Enter fullscreen mode Exit fullscreen mode

Or using the newer command:

git switch -c feature/payment
Enter fullscreen mode Exit fullscreen mode

Creating feature branches keeps your main branch stable.


6. Switch Between Branches

git switch main
Enter fullscreen mode Exit fullscreen mode

or

git checkout main
Enter fullscreen mode Exit fullscreen mode

Always verify you're on the correct branch before making changes.


7. Pull Latest Changes

git pull origin main
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Your teammates can't review your work until it's pushed.


9. See What Changed

git diff
Enter fullscreen mode Exit fullscreen mode

Compare staged changes:

git diff --staged
Enter fullscreen mode Exit fullscreen mode

This is extremely useful before committing.


10. Undo the Last Commit (Without Losing Changes)

If you committed too early:

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

Your changes remain staged, allowing you to edit and recommit.


11. Stash Temporary Work

Need to switch branches without committing unfinished work?

git stash
Enter fullscreen mode Exit fullscreen mode

Restore it later:

git stash pop
Enter fullscreen mode Exit fullscreen mode

Git Stash is perfect when an urgent production issue interrupts your current task.


12. View Remote Repositories

git remote -v
Enter fullscreen mode Exit fullscreen mode

Example:

origin https://github.com/company/project.git
Enter fullscreen mode Exit fullscreen mode

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 diff before 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
Enter fullscreen mode Exit fullscreen mode

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:

👉 https://toolbenchapp.com/

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)