Hero image for 10 Hidden Git Commands to Supercharge Your Workflow 🚀

10 Hidden Git Commands to Supercharge Your Workflow 🚀

By CodexCode4 min read
3 reactions
1
1
0
0
1

Mastering Git: Save Time and Boost Productivity

Let’s be real—Git is both a lifesaver and a source of endless confusion. If you’ve ever found yourself staring at an error message, wondering what just happened, you’re not alone. Sure, you know the basics—git clone, git commit, git push. But there’s a whole world of Git commands out there that can save you time, fix mistakes, and make you look like a Git pro.

As a solo full-stack developer at CodexCode Over time, I’ve discovered some underrated Git tricks that help me work faster and avoid frustration. Let’s dive into 10 lesser-known Git commands that will level up your workflow and optimize your version control skills.

1. git reflog: Undo Like a Time Machine 🕒

Ever thought you lost a commit forever? git reflog is your safety net. It tracks every action you’ve taken, allowing you to recover lost commits, branches, or even entire histories.

bash×
1git reflog

Use case: I once force-pushed the wrong branch and thought my work was gone. git reflog let me recover it instantly.

2. git stash -p: Stash Only What You Need ✂️

You might know git stash, but did you know you can stash only certain parts of a file? -p (patch mode) lets you interactively choose what to stash.

bash×
1git stash -p

Why it’s awesome: Perfect for when you need to stash changes selectively without losing everything.

3. git rev-parse: Extract Info from Git 🕵️‍♂️

Need to get the current branch name, latest commit hash, or root directory? git rev-parse is a secret weapon for scripting and automation.

bash×
1git rev-parse --abbrev-ref HEAD   # Get current branch name
2git rev-parse HEAD                # Get latest commit hash
3git rev-parse --show-toplevel     # Get project root directory

4. git grep: Search Code Like a Boss 🔎

Why open your code editor when you can search right from the terminal?

bash×
1git grep 'function_name'

Use case: Find where a function is defined across all branches without leaving Git.

5. git cherry-pick: Copy Specific Commits 🍒

Sometimes, you need a commit from another branch without merging everything. git cherry-pick does exactly that.

bash×
1git cherry-pick <commit-hash>

Pro tip: Works great when you accidentally commit something to the wrong branch.

6. git worktree: Work on Multiple Branches Simultaneously 🏗️

Tired of constantly switching branches? git worktree lets you check out multiple branches in separate directories.

bash×
1git worktree add ../new-folder <branch-name>

Why it’s awesome: Keeps your projects organized and prevents conflicts between feature branches.

7. git bisect: Pinpoint Bugs with Precision 🔍

Debugging a mysterious bug? git bisect automates the search for the commit that introduced the issue.

bash×
1git bisect start
2git bisect bad  # Mark current commit as bad
3git bisect good <commit-hash>  # Mark an old commit as good

Pro tip: Automate it with a test script:

bash×
1git bisect run ./test-script.sh

Git bisect tutorial, debugging with Git, find bad commits in Git

8. git clean: Wipe Untracked Files 🧹

Got junk files in your repo? git clean removes untracked files and directories.

bash×
1git clean -fd

Warning: This is destructive! Use git clean -fdn to preview first.

9. git shortlog: See Who Did What 👀

Want a clean summary of who contributed to your project? git shortlog gives you a nice overview.

bash×
1git shortlog -sn

Why it’s useful: Great for open-source projects and tracking team contributions.

10. git replace: Fix History Without Rewriting ⏳

Need to update a commit but don’t want to rebase? git replace lets you overlay a new commit without altering history.

bash×
1git replace <old-commit-hash> <new-commit-hash>

Use case: I use this to attach better commit messages to old commits without modifying the Git tree.

Bonus: Create Your Own Git Aliases 🚀

Typing long commands? Save time by setting up Git aliases.

bash×
1git config --global alias.undo 'reset --hard HEAD^'
2git config --global alias.st 'status'
3git config --global alias.last 'log -1 HEAD'

Now, you can simply run:

bash×
1git undo   # Undo last commit
2git st     # Show status
3git last   # Show last commit

Final Thoughts 🏆

Git is packed with powerful commands that can save you hours every week. Whether you’re debugging with git bisect, managing branches with git worktree, or recovering lost commits with git reflog, these hidden gems will make your workflow smoother.

CodexCode

Written by CodexCode

Building the future of web development

Want to discuss about this post?

Join to our community discord & discuss about this post or find more information, resources & tips.

💡 Expert Tips & Tricks
🔥 Hot Development Topics
🤝 Networking Opportunities
🎯 Exclusive Resources

We use cookies to enhance your browsing experience. By clicking 'Accept,' you agree to our use of cookies. Learn more