DEV Community

Cover image for 5 Git Commands You Shouldn’t Ignore
M Mainul Hasan
M Mainul Hasan

Posted on • Originally published at blog.stackademic.com

5 Git Commands You Shouldn’t Ignore

You’re probably already a pro at using Git’s ‘A-list’ commands: git commit, git push, and git pull. But beyond these, there are powerful commands that often fly under the radar. Not only can they save you time, but they can also change the way you think about version control.

1. Git Stash: Safe Your Coding

Imagine You’re deep into coding a new feature, and suddenly, a high-priority bug report interrupts you. You don’t have to rush to commit your half-done code.

Instead, you can just “stash” it away safely. This lets you fix the urgent bugs first and then easily get back to your feature work.

git stash save "Work in progress for new feature"
Enter fullscreen mode Exit fullscreen mode

2. Git Bisect: Bug Detective

Finding a new bug is like looking for a needle in a haystack of commits. Don’t bother going through each one individually — git bisect is a more efficient way to find bugs.

Using a binary search algorithm, it quickly identifies the problematic commit causing the problem.

git bisect start
git bisect bad
git bisect good [good_commit]
Enter fullscreen mode Exit fullscreen mode

3. Git Cherry-Pick: Selective Genius Import

Imagine you’ve spotted a great fix or feature in another branch. Instead of dragging along all the other commits through a merge, why not ‘cherry-pick’ just the genius you need?

git cherry-pick [commit_hash]
Enter fullscreen mode Exit fullscreen mode

4. Git Reflog: Undo Button for Git

Have you ever wished you could roll back a botched git command? Enter git reflog. It keeps a record of every move you’ve made, making it easy to turn back the clock and recover lost commits.

git reflog
Enter fullscreen mode Exit fullscreen mode

5. Git Rebase -i: Commit Curator

Before you release your excellent new feature, cleaning up your commit history is a good idea. Interactive Rebase (git rebase -i) lets you reorder, squash, or amend commits, creating a polished history that’s easy to follow.

git rebase -i [base_commit]
Enter fullscreen mode Exit fullscreen mode

Conclusion

Git offers so much more than the popular commands we use daily. These less-used commands can supercharge your workflow, make it easy to track bugs, and even save your day in case of emergency commits.

So, exploring these Git’s lesser-known features and learning will make your coding workflow smoother. Not only will you become a more capable developer, but you will also take your version control to new heights.

Which of these Git commands are new to you? Have you encountered a situation where one could have been a lifesaver? Share your experiences, tips, and tricks in the comments below.

Feel free to connect with me on Twitter or LinkedIn.

Read Next...

Top comments (2)

Collapse
 
jessekphillips profile image
Jesse Phillips

I think git stash can be ignored, though I still make use of it. Use of --amend and --fixup with proper tools like git gui means you can use commit as a stash but this will be stored in the git database.

Stash is good to move changes to another branch but where git will complain it is editing those files.

Collapse
 
mmainulhasan profile image
M Mainul Hasan

Thanks for sharing your insights! Indeed, using --amend and --fixup with git gui can replicate the stashing function and often feels more streamlined.

While stash has distinct advantages, particularly when shifting changes between branches, it's fascinating to observe how each developer tailors Git commands to their unique workflow and preferences. Thanks for sharing your insights 👩‍💻🚀