DEV Community

Cover image for 10 Git Commands That Will Make Your Team Think You Are a Wizard
Teguh Coding
Teguh Coding

Posted on

10 Git Commands That Will Make Your Team Think You Are a Wizard

Most developers know git commit, git push, and git pull. That covers maybe 20% of what Git can do. The other 80% is where the real power lives — and most teams never touch it.

I have been using Git for years, and I still discover commands that make me stop and think: "Why did I not know this sooner?" This article collects 10 of those commands. Some will save you hours. Some will save your project. All of them are worth knowing.


1. git bisect — Find the Commit That Broke Everything

You push to production. Something breaks. You have 200 commits since the last known-good state. How do you find the culprit?

Binary search.

git bisect start
git bisect bad                  # current commit is broken
git bisect good v2.1.0          # last known good tag or commit hash
Enter fullscreen mode Exit fullscreen mode

Git will checkout the middle commit. You test it. You tell Git if it is good or bad:

git bisect good   # or: git bisect bad
Enter fullscreen mode Exit fullscreen mode

Repeat until Git prints: abc1234 is the first bad commit. You just found your bug in O(log n) steps instead of O(n).

When done:

git bisect reset
Enter fullscreen mode Exit fullscreen mode

2. git reflog — Your Safety Net

You did a hard reset and lost your commits. You force-pushed and overwrote something important. You deleted a branch before merging.

Do not panic. Run:

git reflog
Enter fullscreen mode Exit fullscreen mode

You will see a log of every HEAD movement in your local repo — every checkout, reset, merge, rebase. Every single one. Find the hash you need and:

git checkout abc1234
git checkout -b recovered-branch
Enter fullscreen mode Exit fullscreen mode

Reflog is your time machine. It keeps history for 90 days by default. Use it before you ever think about giving up.


3. git stash — More Powerful Than You Think

You already know git stash. But do you know these?

git stash push -m "WIP: auth refactor"   # give your stash a name
git stash list                            # see all stashes
git stash apply stash@{2}                 # apply a specific stash
git stash pop stash@{0}                   # apply and drop
git stash branch feature/auth stash@{1}  # create branch from stash
Enter fullscreen mode Exit fullscreen mode

And the most underused option:

git stash push --patch   # interactively choose which changes to stash
Enter fullscreen mode Exit fullscreen mode

This lets you stash only part of your working tree — incredibly useful when you have mixed changes and need to switch context fast.


4. git log — Stop Using It Wrong

Plain git log is an eyesore. Try this instead:

git log --oneline --graph --decorate --all
Enter fullscreen mode Exit fullscreen mode

Or set an alias:

git config --global alias.lg "log --oneline --graph --decorate --all"
git lg
Enter fullscreen mode Exit fullscreen mode

Other useful log tricks:

git log --author="Teguh"              # commits by author
git log --since="2 weeks ago"         # time-filtered
git log --grep="fix: auth"            # search commit messages
git log -S "passwordHash"             # find when a string was added/removed
git log -- path/to/file.js            # history of a specific file
Enter fullscreen mode Exit fullscreen mode

The -S flag (pickaxe) is especially powerful. It searches the diff content, not the message. Perfect for tracking down when a function appeared or disappeared.


5. git cherry-pick — Surgical Commit Transfer

You have a fix on one branch that you need on another — without merging the whole branch.

git cherry-pick abc1234
Enter fullscreen mode Exit fullscreen mode

Pick a range:

git cherry-pick abc1234..def5678
Enter fullscreen mode Exit fullscreen mode

Apply without committing yet (so you can edit):

git cherry-pick --no-commit abc1234
Enter fullscreen mode Exit fullscreen mode

Useful scenario: a hotfix on main that also needs to go to the release/2.x support branch. Cherry-pick it cleanly instead of creating a mess with merges.


6. git worktree — Multiple Branches at Once

You are deep in a feature. An urgent bug comes in on main. Normally you stash, switch, fix, switch back, pop stash, deal with conflicts.

With worktrees:

git worktree add ../hotfix main
cd ../hotfix
# fix the bug here
git commit -am "fix: critical auth bypass"
git push
cd -   # back to your feature
Enter fullscreen mode Exit fullscreen mode

You now have two working directories from the same repo, each on a different branch, completely independently. No stashing. No context loss.

git worktree list    # see all worktrees
git worktree remove ../hotfix  # clean up when done
Enter fullscreen mode Exit fullscreen mode

7. git commit --fixup and git rebase --autosquash

You made a commit. Then you realized you forgot something small. Instead of making a vague "fix" commit, do this:

git add .
git commit --fixup=abc1234   # abc1234 is the commit you want to fix
Enter fullscreen mode Exit fullscreen mode

This creates a commit named fixup! original commit message. Later, when you clean up:

git rebase -i --autosquash origin/main
Enter fullscreen mode Exit fullscreen mode

Git automatically moves and squashes your fixup commits into their targets. Your history stays clean without manual reordering in the interactive rebase editor.


8. git diff --word-diff

Reading a diff on prose or long strings is painful with the default line-level diff:

git diff --word-diff
Enter fullscreen mode Exit fullscreen mode

Output shows exactly which words changed instead of the whole line. Essential when reviewing documentation changes, long strings, or configuration files where only a value changed.

git diff --word-diff=color  # color-coded inline
Enter fullscreen mode Exit fullscreen mode

9. git blame — But Smarter

git blame shows who wrote each line. But what if the line was moved from another file, or was reformatted?

git blame -w          # ignore whitespace changes
git blame -M          # detect moved lines within the file
git blame -C          # detect lines copied from other files
git blame -C -C       # look across all commits
Enter fullscreen mode Exit fullscreen mode

Combined:

git blame -w -C -C -C path/to/file.js
Enter fullscreen mode Exit fullscreen mode

This cuts through reformatting commits and file renames to show you the true origin of each line. No more blaming the person who just ran the formatter.


10. git maintenance — Let Git Optimize Itself

Over time, Git repos accumulate loose objects, stale pack files, and other cruft. On large repos, this slows everything down.

git maintenance start
Enter fullscreen mode Exit fullscreen mode

This registers the repo with a background scheduled task (using system cron or launchd) that runs:

  • gc for garbage collection
  • commit-graph updates for faster traversal
  • prefetch to keep remote refs fresh
  • pack-refs for ref lookup performance

Set it and forget it. Git handles its own housekeeping so you do not have to.


Putting It Together

Here is a scenario that uses multiple commands from this list:

  1. You are working on a feature. Urgent bug comes in.
  2. git worktree add ../bugfix main — no stashing needed.
  3. Fix, commit, push. Back to feature branch.
  4. You realize the fix also applies to your feature branch: git cherry-pick abc1234.
  5. Three commits later you find a regression: git bisect narrows it to one commit in minutes.
  6. You force-pushed by accident: git reflog rescues the lost commits.
  7. Before submitting your PR, clean history with --fixup + --autosquash.

Git is not just a version control system. It is a time machine, a collaboration tool, and a debugging assistant all in one. Most developers use maybe 10% of it. The commands above are your invitation to use the other 90%.


Which of these did you already know? Which surprised you? Drop it in the comments.

Top comments (1)

Collapse
 
harsh2644 profile image
Harsh

Amazing list! I had no idea about git bisect — definitely going to try it next time something breaks in production. Thanks for sharing!