DEV Community

Cover image for 20+ Git Commands Every Software Engineer Should Actually Know
Nilesh Raut
Nilesh Raut

Posted on

20+ Git Commands Every Software Engineer Should Actually Know

Most engineers use Git every day—but only a handful of commands.
That’s fine… until something goes wrong.

A bad merge.
A wrong commit.
A force-push panic.

This list covers 20+ Git commands you’ll actually use in real projects, with one-line explanations so you know what they do and when to use them.


Core Git Commands Basics

1. git init

Creates a new Git repository in the current directory.

git init
Enter fullscreen mode Exit fullscreen mode

2. git clone

Downloads an existing remote repository to your local machine.

git clone <repo-url>
Enter fullscreen mode Exit fullscreen mode

3. git status

Shows the current state of files (modified, staged, untracked).

git status
Enter fullscreen mode Exit fullscreen mode

4. git add

Stages files so they’re included in the next commit.

git add .
git add file.js
Enter fullscreen mode Exit fullscreen mode

5. git commit

Saves staged changes as a snapshot with a message.

git commit -m "message"
Enter fullscreen mode Exit fullscreen mode

6. git push

Uploads local commits to the remote repository.

git push origin main
Enter fullscreen mode Exit fullscreen mode

7. git pull

Fetches remote changes and merges them into your branch.

git pull
Enter fullscreen mode Exit fullscreen mode

Branching & Navigation

8. git branch

Lists branches or creates a new branch.

git branch
git branch feature-x
Enter fullscreen mode Exit fullscreen mode

9. git checkout

Switches branches or restores files.

git checkout feature-x
Enter fullscreen mode Exit fullscreen mode

10. git switch

A cleaner, modern way to switch branches.

git switch main
Enter fullscreen mode Exit fullscreen mode

11. git merge

Combines another branch into the current branch.

git merge feature-x
Enter fullscreen mode Exit fullscreen mode

12. git log

Shows commit history for the current branch.

git log --oneline --graph
Enter fullscreen mode Exit fullscreen mode

Undoing Mistakes

13. git reset

Moves HEAD and optionally discards commits or changes.

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

14. git revert

Creates a new commit that safely undoes an older commit.

git revert <commit-hash>
Enter fullscreen mode Exit fullscreen mode

15. git checkout -- <file>

Discards local changes to a specific file.

git checkout -- index.js
Enter fullscreen mode Exit fullscreen mode

Temporary Work

16. git stash

Temporarily saves uncommitted changes.

git stash
git stash pop
Enter fullscreen mode Exit fullscreen mode

17. git stash list

Shows all saved stashes.

git stash list
Enter fullscreen mode Exit fullscreen mode

Working With Remotes

18. git remote -v

Displays configured remote repositories.

git remote -v
Enter fullscreen mode Exit fullscreen mode

19. git fetch

Downloads remote changes without merging them.

git fetch
Enter fullscreen mode Exit fullscreen mode

Inspecting Changes

20. git diff

Shows differences between files, commits, or stages.

git diff
git diff --staged
Enter fullscreen mode Exit fullscreen mode

21. git blame

Shows who last modified each line of a file.

git blame file.js
Enter fullscreen mode Exit fullscreen mode

22. git show

Displays detailed information about a specific commit.

git show <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Cleanup & Recovery

23. git clean

Removes untracked files from the working directory.

git clean -fd
Enter fullscreen mode Exit fullscreen mode

24. git reflog

Shows every move of HEAD, even deleted or lost commits.

git reflog
Enter fullscreen mode Exit fullscreen mode

How Senior Engineers Actually Use Git

Senior engineers:

  • check git status constantly,
  • prefer revert over reset on shared branches,
  • use fetch before risky merges,
  • rely on reflog when things go wrong.

Git isn’t just version control—it’s your safety net.


Final Thoughts

You don’t need to memorize Git.
You need to understand enough to recover when things break.

Master these commands and you’ll:

  • move faster,
  • panic less,
  • and collaborate better.

Git won’t make you a better engineer—but not knowing Git can absolutely make you a worse one.

Top comments (1)

Collapse
 
zeroxdesignart profile image
Mauricio Sanchez

thank you