20+ Git Commands Every Software Engineer Should Actually Know
Source: Dev.to
Git Commands Basics
git init
Creates a new Git repository in the current directory.
git initgit clone
Downloads an existing remote repository to your local machine.
git clone git status
Shows the current state of files (modified, staged, untracked).
git statusgit add
Stages files so they’re included in the next commit.
git add .
git add file.jsgit 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 maingit pull
Fetches remote changes and merges them into your branch.
git pullgit branch
Lists branches or creates a new branch.
git branch
git branch feature-xgit checkout
Switches branches or restores files.
git checkout feature-xgit switch
A cleaner, modern way to switch branches.
git switch maingit merge
Combines another branch into the current branch.
git merge feature-xgit log
Shows commit history for the current branch.
git log --oneline --graphgit reset
Moves HEAD and optionally discards commits or changes.
git reset --soft HEAD~1
git reset --hard HEAD~1git 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.jsgit stash
Temporarily saves uncommitted changes.
git stash
git stash popgit stash list
Shows all saved stashes.
git stash listgit remote -v
Displays configured remote repositories.
git remote -vgit fetch
Downloads remote changes without merging them.
git fetchgit diff
Shows differences between files, commits, or stages.
git diff
git diff --stagedgit blame
Shows who last modified each line of a file.
git blame file.jsgit show
Displays detailed information about a specific commit.
git show git clean
Removes untracked files from the working directory.
git clean -fdgit reflog
Shows every move of HEAD, even deleted or lost commits.
git reflogTips for Senior Engineers
- Check
git statusconstantly. - Prefer
git revertovergit reseton shared branches. - Use
git fetchbefore risky merges. - Rely on
git reflogwhen 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.