DEV Community

Cover image for 5 Git Commands Every Developer Should Know
Caelora
Caelora

Posted on

5 Git Commands Every Developer Should Know

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

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

Instead of showing long commit details, this command displays a clean, compact history.

Example:

f82d4f1 Fix login bug
1ab8c72 Update README
8ce44f0 Add authentication
Enter fullscreen mode Exit fullscreen mode

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

Or, with newer Git versions:

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

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

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

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

For example:

git help commit
Enter fullscreen mode Exit fullscreen mode

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 status
  • git log --oneline
  • git switch -c
  • git restore --staged
  • git 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)

Collapse
 
merbayerp profile image
Mustafa ERBAY

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.