20+ Git Commands Every Software Engineer Should Actually Know

Published: (January 30, 2026 at 11:07 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Git Commands Basics

git init

Creates a new Git repository in the current directory.

git init

git clone

Downloads an existing remote repository to your local machine.

git clone 

git status

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

git status

git add

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

git add .
git add file.js

git commit

Saves staged changes as a snapshot with a message.

git commit -m "message"

git push

Uploads local commits to the remote repository.

git push origin main

git pull

Fetches remote changes and merges them into your branch.

git pull

git branch

Lists branches or creates a new branch.

git branch
git branch feature-x

git checkout

Switches branches or restores files.

git checkout feature-x

git switch

A cleaner, modern way to switch branches.

git switch main

git merge

Combines another branch into the current branch.

git merge feature-x

git log

Shows commit history for the current branch.

git log --oneline --graph

git reset

Moves HEAD and optionally discards commits or changes.

git reset --soft HEAD~1
git reset --hard HEAD~1

git revert

Creates a new commit that safely undoes an older commit.

git revert 

git checkout --

Discards local changes to a specific file.

git checkout -- index.js

git stash

Temporarily saves uncommitted changes.

git stash
git stash pop

git stash list

Shows all saved stashes.

git stash list

git remote -v

Displays configured remote repositories.

git remote -v

git fetch

Downloads remote changes without merging them.

git fetch

git diff

Shows differences between files, commits, or stages.

git diff
git diff --staged

git blame

Shows who last modified each line of a file.

git blame file.js

git show

Displays detailed information about a specific commit.

git show 

git clean

Removes untracked files from the working directory.

git clean -fd

git reflog

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

git reflog

Tips for Senior Engineers

  • Check git status constantly.
  • Prefer git revert over git reset on shared branches.
  • Use git fetch before risky merges.
  • Rely on git reflog when things go wrong.

Git isn’t just version control—it’s your safety net. You don’t need to memorize every command; understand enough to recover when things break. Mastering these commands helps you move faster, panic less, and collaborate better. Not knowing Git can make you a worse engineer.

Back to Blog

Related posts

Read more »