8 Must-know Git Tricks for Efficient and Productive Code Management

Ketan Gupta
3 min readJan 18, 2023

--

Git is a powerful tool for managing code, but it can be overwhelming for beginners. In this article, I’ll share some of the most useful Git tricks that will help you become more efficient and productive.

  1. Stashing changes: Sometimes, you may be in the middle of working on a feature or fixing a bug and you need to switch to another branch to work on something else. You don’t want to commit your changes, but you don’t want to lose them either. This is where the git stash command comes in handy. It allows you to save your changes temporarily without committing them. You can later apply the stashed changes using git stash apply.
  2. Visualizing the commit history: The git log --graph command shows a visual representation of your commit history, including branches and merges. It's a great way to see the overall flow of your project and understand how different branches fit together. You can also use gitk command to open a GUI of the commit history.
  3. Checking changes before committing: The git diff command shows the differences between your current changes and the last committed version. It's a great way to see what you've changed before committing your code, and it can help you avoid committing unintended changes.
  4. Understanding code ownership: The git blame command shows the last person who modified each line of a file, along with the commit hash and date. This is useful for debugging or understanding why a particular piece of code was written a certain way.
  5. Cherry-picking commits: The git cherry-pick command allows you to apply a specific commit from one branch to another. This is useful when you want to bring a bug fix or feature from one branch to another, without merging the entire branch.
  6. Finding the commit that introduced a bug: The git bisect command is a binary search method to find the commit that introduced a bug. It allows you to quickly find the commit that introduced an issue by narrowing down the search through a process of elimination.
  7. Undoing commits: The git reset command allows you to undo commits, it's useful when you need to go back to a previous state of the repository, you can use it to un-do commits, and also to un-do merge or pull.
  8. Interactive rebase: The git rebase -i command allows you to interactively rebase a branch. It opens a text editor where you can edit, reorder, or squash commits, before replaying them on top of a different branch. This can help you keep your commit history clean and easy to read.

These are just a few of the many powerful Git tricks available. With practice and experience, you’ll find the tools and techniques that work best for you and your projects. Remember that Git is a powerful tool that can be used in many different ways, so don’t be afraid to experiment and find the workflow that works best for you.

--

--

Ketan Gupta

Techie exploring Life. Providing fresh perspectives and thought-provoking insights. Follow for more.