</>StackKit
</>StackKit

Developer tutorials & guides

Git branching diagram
Git

20 Git Commands Every Developer Must Know in 2025

Master the essential Git commands that cover everything from daily workflow to fixing mistakes and collaborating with teams.

S
Sam Rivera
April 25, 20258 min read
#git#version-control#github#devops

Why Git Mastery Matters

Git is the backbone of modern software development. Whether you work alone or in a team of 200, understanding Git at a deep level is what separates developers who lose work and create merge chaos from those who ship confidently.

This guide covers 20 commands — not just their syntax, but when and why to use them.


Daily Workflow Commands

1. git status

git status

Your first command every morning. Shows modified files, staged changes, and untracked files at a glance.

2. git add

git add src/components/Button.tsx   # specific file
git add src/                        # whole directory
git add -p                          # interactive staging (best practice)

The -p flag lets you stage changes hunk by hunk — perfect for keeping commits focused.

3. git commit

git commit -m "feat: add dark mode toggle to settings"

Write commits in the imperative mood. Use Conventional Commits format (feat:, fix:, docs:) for clean changelogs.

4. git push / git pull

git push origin main
git pull origin main --rebase    # cleaner history than merge

Branch Management

5. git branch

git branch                    # list local branches
git branch feature/login      # create new branch
git branch -d feature/login   # delete merged branch
git branch -D feature/login   # force delete

6. git checkout / git switch

git switch main               # modern syntax
git switch -c feature/auth    # create and switch

7. git merge

git merge feature/login --no-ff    # preserves merge commit

8. git rebase

git rebase main    # replay your branch on top of main

Use rebase for a linear history. Use merge for preserving branch topology.


Undoing Things

9. git restore

git restore src/app.ts          # discard working directory changes
git restore --staged src/app.ts # unstage a file

10. git reset

git reset HEAD~1          # undo last commit, keep changes staged
git reset --soft HEAD~1   # keep changes staged
git reset --hard HEAD~1   # discard everything — use carefully

11. git revert

git revert abc1234   # create a new commit that undoes abc1234

Always prefer revert over reset on shared branches.


Inspection & History

12. git log

git log --oneline --graph --all   # beautiful visual history
git log -p src/auth.ts            # history of a specific file

13. git diff

git diff                    # unstaged changes
git diff --staged           # staged changes
git diff main feature/auth  # between branches

14. git blame

git blame src/auth.ts   # who wrote each line and when

15. git show

git show abc1234   # full details of a specific commit

Advanced Techniques

16. git stash

git stash push -m "wip: half-done auth"
git stash list
git stash pop

Stash is your escape hatch when you need to context-switch without committing.

17. git cherry-pick

git cherry-pick abc1234   # apply a specific commit to current branch

18. git bisect

git bisect start
git bisect bad         # current commit is broken
git bisect good v2.0   # this tag was working

Binary search through commits to find exactly which one introduced a bug.

19. git reflog

git reflog   # full history of HEAD movements — your safety net

If you accidentally deleted a branch or did a hard reset, reflog can get it back.

20. git tag

git tag v1.2.0 -m "Release 1.2.0"
git push origin --tags

Conclusion

These 20 commands cover 95% of everything you'll do with Git day to day. The ones that separate good developers from great ones are rebase, bisect, reflog, and the interactive staging with -p. Practice them in a test repo until they're muscle memory.

#git#version-control#github#devops