25 Git Commands Every Developer Should Know

Beyond the basics — the Git commands that separate beginners from productive developers.

Daily Essentials

1. git status -sb

Short branch status — much cleaner than the default verbose output.

git status -sb
## main...origin/main
 M src/app.tsx
?? new-file.ts

2. git add -p

Stage changes interactively, hunk by hunk. This lets you create focused commits even when you've made multiple unrelated changes.

git add -p
# Review each change and type y/n to stage or skip

3. git commit --amend --no-edit

Add staged changes to the last commit without changing its message.

git add forgotten-file.ts
git commit --amend --no-edit

4. git stash push -m "description"

Named stashes are much easier to manage than anonymous ones.

git stash push -m "WIP: auth refactor"
git stash list
# stash@{0}: On main: WIP: auth refactor

5. git log --oneline --graph --all

Visual branch history in the terminal — essential for understanding merge topology.

git log --oneline --graph --all
* a1b2c3d (HEAD -> feature) Add login form
| * d4e5f6g (main) Fix header
|/
* 1234567 Initial commit

Branching Power Moves

6. git switch -c feature/name

Modern replacement for git checkout -b. Clearer intent.

7. git branch --merged | grep -v main

List branches already merged into main — safe to delete.

git branch --merged | grep -v main | xargs git branch -d

8. git rebase -i HEAD~3

Interactive rebase to squash, reorder, or edit the last 3 commits.

9. git cherry-pick commit-hash

Apply a specific commit from another branch to your current branch.

git cherry-pick a1b2c3d
# Applies that exact commit to current branch

10. git merge --no-ff feature

Always create a merge commit, even for fast-forward merges. Better history.

Debugging & Investigation

11. git bisect

Binary search to find the commit that introduced a bug.

git bisect start
git bisect bad          # Current commit is bad
git bisect good v2.0    # v2.0 was good
# Git checks out middle commit, you test, mark good/bad
git bisect reset        # Done

12. git blame -L 10,20 file.ts

Who changed lines 10-20? When and why?

13. git diff --stat main

Summary of changes between current branch and main.

14. git log -S "functionName"

Find commits that added or removed a specific string. The "pickaxe" search.

15. git reflog

Your safety net — shows every HEAD position change. Recover "lost" commits.

git reflog
# Find the commit you want to recover
git checkout HEAD@{5}

Cleanup & Maintenance

16. git clean -fd

Remove untracked files and directories. Add -n for dry run first.

17. git remote prune origin

Remove local references to deleted remote branches.

18. git gc --aggressive

Garbage collect and optimize the repository.

19. git worktree add ../feature-branch feature

Check out a branch in a separate directory. Work on two branches simultaneously.

20. git reset --soft HEAD~1

Undo the last commit but keep all changes staged.

Advanced Workflows

21. git rebase --onto

Transplant a branch onto a different base.

# Move feature from old-base to new-base
git rebase --onto new-base old-base feature

22. git push --force-with-lease

Safer than --force — refuses to push if someone else pushed since your last fetch.

23. git diff --word-diff

Show changes at the word level instead of line level.

24. git shortlog -sn

Leaderboard — commit counts by author.

25. git archive --format=zip HEAD -o project.zip

Create a clean zip of the repo without .git history.

Bonus: Useful Git Aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st "status -sb"
git config --global alias.lg "log --oneline --graph --all"
git config --global alias.undo "reset --soft HEAD~1"

Want more? Check out our free developer tools — JSON formatter, regex tester, hash generator, and more.