Git Pills – Adding a Git Bash facility to Visual Studio


Visual Studio
2013 has a good Git integration; I like it, and I use it for committing while developing C# and .NET stuff. But…

For some other operations (branch, merge, and so on), I still prefer the Bash shell, inasmuch typing command now and then makes me feel better :)

Firing a new Bash shell from VS’s Git plugin is not possible, unfortunately, and I did not found any extension which can bridge this gap; the quickest thing to do, for a lazy dev like me, is to open the solution containing folder and then use the default “Git Bash” option from the right click menu:

Visual Studio 2013 - Open solution folder Git Bash

Given that I’m lazy, but one of that lazy developers Bill Gates likes, I looked for a quick solution to get out from this annoying situation, and I found a dirty trick to have a simple toolbar button to click (and a shortcut to type) to open a Bash shell in the solution folder I’m working on.

Bill-Gates-Lazy-Person

First of all, we need to add a new external tool to Visual Studio; you can do this using TOOLS menu and then clicking on “External Tools…” entry:

Visual-Studio-External-Tools

A this point we can configure the Bash command in the External Windows just opened:

Git-Bash-External-Command

As you can see, we take advantage of $(SolutionDir) variable to get a Bash shell in the right directory.
Before confirming by OK button, please commit to memory the command order; Visual Studio names external commands by numbers, so, in this example, my “Bash” command will be the “External Command 4“.

Now that we have a new External Command, we can generate a new toolbar button to click related to it; I suggest to add the button to the Standard Toolbar, because it is (generally) always available:

Visual-Studio-Add-Toolbal-Customize

Now add the new command button to Standard toolbar:

Visual-Studio-Add-Toolbar-Command

From “Tools” category, choose the External Command accordingly to your number; mine is the forth, “External Command 4“:

Visual-Studio-Add-Toolbar-Command-Tools-External-Command

Then click OK.

Now it’s time to give to that button a meaningful name; rename it to “Git Bash” (or whatever you want….) as I did:

Visual-Studio-Add-Toolbar-Command-Rename

My suggestion is to move that button at the end of the toolbar, so it is more easy to find:

Visual-Studio-Add-Toolbar-Command-Git-Bash

At the end, if you want, you can click on the “Keyboard” button and assign a shortcut for that command:

Visual-Studio-Toolbar-Command-Keyboard-Shortcut

I choose the Ctrl+B+B  shortcut, you can choose the one you prefer; then click Assign and at the end OK button to terminate.

Visual-Studio-Toolbar-Git-Bash-Button

Well, we have done. Happy Bashing :)

Ciao,
Nando :)

Leave a Reply

Your email address will not be published. Required fields are marked *