10 Lesser-Known Git Commands That Will Level Up Your Workflow
If you’re a developer, you’re probably using Git every day. And chances are, most of the time you’re typing the same five or six commands: git add, git commit, git push, git pull, git checkout... you know the drill.
But Git is a feature-rich version control system with many powerful commands that don’t get as much attention — even though they can save time, reduce errors, and boost productivity.
In this article, I’ll walk you through 10 Git commands that many developers overlook, and explain how each one can make your workflow smoother and smarter, with practical examples included.
1. git switch
🧭 A Modern, Clearer Alternative to checkout for Switching Branches
git switch feature/login
Instead of using the old git checkout to switch branches, use git switch. It’s cleaner and purpose-built for navigating between branches.
2. git restore
🧹 A Safe Way to Discard Changes in Your Working Directory
git restore index.php
Use this command to discard local changes in your working directory before staging.
Example: You’ve edited style.css, but want to undo it completely:\
git restore style.css
Need to undo a staged file (before committing)?
git restore --staged index.php
Pro tip: Want to reset everything in the directory?
git restore .
3. git log — oneline — graph — all
🌲 Visualize Your Git History as a Graph
git log --oneline --graph --all
This command shows a compact commit history with a visual branch structure. It’s an amazing way to understand how branches merge and diverge, especially when resolving conflicts or reviewing PR history.
4. git reflog
🔙 Recover Lost Commits and Branches
git reflog
Think of git reflog as your Git history including the mistakes.
Example: You accidentally ran:
git reset --hard HEAD~3
Now your latest 3 commits are gone… but not really! Run:
git reflog
You’ll see something like:
c3e4f4b HEAD@{0}: reset: moving to HEAD~3
e1f3a2b HEAD@{1}: commit: Add image upload
b4d1e7a HEAD@{2}: commit: Update navbar styles
Now restore a commit like this:
git checkout e1f3a2b
5. git cherry -v
🍒 See Which Commits Are Unique to Your Branch
git cherry -v main
This compares your current branch to another (like main) and shows commits that exist only in your current branch.
Example:
You’re on feature/payment and want to check which commits haven’t been merged yet:
Recommended by LinkedIn
git cherry -v main
Output:
+ a1b2c3d Add Stripe integration
+ d4e5f6g Create payment success screen
6. git shortlog -sn
👥 See a Summary of Contributions by Each Developer
git shortlog -sn
Need to see who’s been most active in your repo?
Example output:
134 Farshad
45 Alice
21 Bob
7. git diff — staged
🕵️ Double-Check What You’re About to Commit
git diff --staged
This shows what you’ve added to the staging area (via git add), and what will be committed.
8. git clean -fd
🧼 Clean Up Untracked Files and Directories
git clean -fd
Deletes all untracked files and folders — useful when your repo feels “dirty” after testing or building.
🛑 Warning: This action is destructive — it cannot be undone!
9. git bisect
🔍 Find the Commit That Introduced a Bug
git bisect start
git bisect bad # current commit is broken
git bisect good abc1234 # known working commit
Git helps you do a binary search through your commit history to find the exact commit that broke your app.
Example:
You know the app was working in commit abc1234, but now it's broken.
Start bisecting:
git bisect start
git bisect bad
git bisect good abc1234
Git checks out a middle commit. You test it and mark it:
git bisect good # or bad
Repeat until Git says:
abcde12 is the first bad commit
Fix it, then end bisecting:
git bisect reset
10. git worktree
🌳 Work on Multiple Branches at Once Without Cloning Again
git worktree add ../feature-ui feature/ui-update
This creates a separate working directory for a different branch — no need to stash or switch back and forth.
Example:
You’re working on feature/backend-api, but need to test something on feature/ui.\git worktree add ../ui-folder feature/ui
Now you have two folders, each with its own active branch. Perfect for: