DEV Community

Alex Spinov
Alex Spinov

Posted on

Git Commands Nobody Teaches You (But Everyone Should Know)

I used Git for 3 years before I learned git bisect. Three years of manually checking commits to find bugs.

Here are the Git commands that changed how I work — the ones that never show up in beginner tutorials.

1. git bisect — Find the Exact Commit That Broke Things

# Start bisecting
git bisect start
git bisect bad          # Current commit is broken
git bisect good v1.0.0  # This version worked

# Git checks out a commit in the middle
# Test it, then tell Git:
git bisect good  # or
git bisect bad

# Repeat until Git finds the exact commit
# git bisect reset when done
Enter fullscreen mode Exit fullscreen mode

Real use: Found a performance regression across 500 commits in under 2 minutes. Without bisect, I'd still be looking.

2. git stash — with a Name

Everyone knows git stash. But do you name your stashes?

# BAD — "what was this stash again?"
git stash

# GOOD
git stash push -m "WIP: auth refactor, need to fix token refresh"

# List stashes
git stash list
# stash@{0}: On main: WIP: auth refactor, need to fix token refresh

# Apply specific stash
git stash apply stash@{0}
Enter fullscreen mode Exit fullscreen mode

3. git log — But Actually Useful

# See what changed in each commit (one line per commit)
git log --oneline --graph --all

# Find who wrote a specific line
git log -S "function_name" --oneline

# See commits by a specific author this week
git log --author="Alex" --since="1 week ago" --oneline

# See diff statistics
git log --stat --oneline -5
Enter fullscreen mode Exit fullscreen mode

4. git reflog — Undo Almost Anything

# "I accidentally reset --hard and lost my work!"
git reflog
# Find the commit hash BEFORE the reset
git checkout <hash>
# Or create a branch from it
git branch recovered <hash>
Enter fullscreen mode Exit fullscreen mode

reflog is your safety net. It tracks every HEAD movement — even ones you can't see in git log.

5. git worktree — Multiple Branches at Once

# Work on a hotfix WITHOUT switching branches
git worktree add ../hotfix-branch hotfix/critical-bug

# Now you have two directories:
# ./myproject        → main branch
# ../hotfix-branch   → hotfix branch

# Clean up when done
git worktree remove ../hotfix-branch
Enter fullscreen mode Exit fullscreen mode

Why this is huge: No more stashing, switching branches, rebuilding node_modules. Each worktree has its own working directory.

6. git cherry-pick — Steal One Commit

# Take a single commit from another branch
git cherry-pick abc123

# Take a range of commits
git cherry-pick abc123..def456

# Cherry-pick without committing (just stage the changes)
git cherry-pick --no-commit abc123
Enter fullscreen mode Exit fullscreen mode

Perfect for backporting a bugfix to a release branch.

7. git blame — But Smarter

# Normal blame
git blame app/auth.py

# Ignore whitespace changes
git blame -w app/auth.py

# Show the commit BEFORE the last change (go deeper)
git blame -L 10,20 app/auth.py  # Lines 10-20 only

# Ignore specific commits (e.g., formatting PRs)
echo "abc123" >> .git-blame-ignore-revs
git config blame.ignoreRevsFile .git-blame-ignore-revs
Enter fullscreen mode Exit fullscreen mode

8. git diff — What You Actually Want

# Diff of staged changes (what you're about to commit)
git diff --staged

# Diff with word-level granularity
git diff --word-diff

# Diff only file names
git diff --name-only main..feature-branch

# Diff statistics
git diff --stat main..feature-branch
Enter fullscreen mode Exit fullscreen mode

9. git clean — Remove Untracked Files Safely

# See what would be removed (dry run)
git clean -n

# Remove untracked files
git clean -f

# Remove untracked files AND directories
git clean -fd

# Interactive mode — choose what to delete
git clean -i
Enter fullscreen mode Exit fullscreen mode

10. Aliases That Save Hours

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.last "log -1 HEAD --stat"
git config --global alias.visual "log --oneline --graph --all"
git config --global alias.undo "reset HEAD~1 --mixed"
Enter fullscreen mode Exit fullscreen mode

Now git visual shows a beautiful branch graph. git undo reverses the last commit without losing changes.

Cheatsheet

Command Use When
bisect Finding which commit broke something
stash -m Saving WIP with context
reflog Recovering lost work
worktree Working on multiple branches
cherry-pick Backporting fixes
blame -w Finding who wrote something (ignoring formatting)
clean -n Cleaning up untracked files safely

More developer tools: Awesome Developer Tools 2026 | GitHub Actions Templates


What's your most-used Git command that you learned "too late"? Mine was definitely bisect. 👇

Dev tools at github.com/Spinov001 — 195+ repos

Top comments (0)