Creating a Bash Alias for Visual Git Diffs
While I’m a big fan of using Git from the CLI, there are some things that are better with a GUI. If you’re a developer who frequently uses Git and TortoiseGit, you might find it handy to create a Bash alias that opens the TortoiseGit diff window directly from the command line. This can save you time and streamline your workflow. In this post, I’ll guide you through the steps to create a Bash alias called git-diff
that does just that.
Prerequisites
Before we start, make sure you have the following installed:
- Git: You can download it from git-scm.com.
- TortoiseGit: Download it from tortoisegit.org.
Step-by-Step Guide
Locate TortoiseGitProc.exe: First, find the path to
TortoiseGitProc.exe
. This is typically located in the TortoiseGit installation directory. For example, it might be:C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe
Open Your Bash Profile: Open your
.bashrc
or.bash_profile
file in a text editor. You can do this with the following command:nano ~/.bashrc
Create the Alias: Add the following line to create the git-diff alias. Replace the path with the actual path to your TortoiseGitProc.exe:
alias git-diff='TortoiseGitProc.exe /command:diff'
Save and Close: Save the file and close the text editor. If you’re using
nano
, you can do this by pressingCTRL + X
, thenY
, andEnter
.Reload Your Bash Profile: Apply the changes by reloading your Bash profile:
source ~/.bashrc
Using the Alias
Now, you can use the git-diff
alias to open the TortoiseGit diff window. For example, to see the differences between your working directory and the last commit, you can run:
git-diff
Conclusion
Creating a Bash alias for TortoiseGit diff can significantly speed up your workflow by allowing you to quickly open the diff window from the command line. This simple setup can save you time and make your development process more efficient.
I always recommend software engineers carefully inspect the content in their commits before pushing it up. This reduces the likelihood of pushing inadvertent content in your commits.
Happy coding!