integrating Git Bash with Visual Studio

Visual StudioGit

Visual Studio Problem Overview


I have a windows version of Git Bash, and I want to use it with my Visual Studio Projects. What I want is a way of tweaking some setting so that one click can get Bash opened with the directory on the current visual studio project.

It would be great if there's a way to set up short cut in Git Bash for directories, so that one command can get me to a preset directory.

Visual Studio Solutions


Solution 1 - Visual Studio

Launch Git Bash from Visual Studio

In Visual Studio Menu Bar: Tools -> External Tools -> Add New

Configuration:

Name: Git Bash

Command: c:\Program Files (x86)\git\bin\sh.exe

Args: --login -i

Initial Dir : $(SolutionDir)

Solution 2 - Visual Studio

Visual Studio 2019 after v16.6 comes with an integrated terminal similar to the one in Visual Studio Code but its configuration dialog is really buggy as of now. It also doesn't come with a preconfigured git bash, so in order to make it work, you'll have to work around the bugs and create the configuration.

  1. Go to "Tools -> Options" then "Environment -> Terminal"
  2. Before changing anything, click the Add button.
  3. If the bug is present, you will see that your newly created profile has "(Default)" printed behind its name. You now have two default profiles and the integrated terminal as well as the configuration dialog will do weird stuff. If that is the case select the the second profile, i.e. the one that doesn't say "(Default)", click "Set as Default." Now there should only be one default profile left, and everything should behave as normal. In particular, you can set the default to whatever you want. Just make sure that you don't have the default profile selected when you create a new profile because then you'll end up with two default profiles again. It is important to always keep a second profile around, because otherwise you can only add default profiles, which breaks the GUI.
  4. Configure the bash shell: set the name to something you like (I use "git bash" because I"m boring), as executable use c:\program files\git\bin\bash.exe, as Arguments use --login -i. The shell will be started in your solution's base directory.

You should now be able to use bash in the integrated terminal via the default shortcut Ctrl + ` or via View -> Terminal in the menu.

Solution 3 - Visual Studio

In VS2017 I added mine by going to Tools -> External Tools -> Add

  • Title: Git Bash
  • Command: C:\Program Files\Git\git-bash.exe
  • Initial directory: $(SolutionDir)

Note: Use Output window runs the command and puts any output into the Output window. This is useful for commands that just return some data so I didn't check it.

If you want to create a shortcut for it:

  1. Use MoveUp to move 'Git Bash' to the 1st position.
  2. Go to Tools -> Options -> Environment -> Keyboard and search for Tools.ExternalCommand1
  3. Assign shortcut

Solution 4 - Visual Studio

Have a look at Git Source Control Provider: http://gitscc.codeplex.com/

It has Visual Studio integration for Git and one of the options is to bring up Git Bash.

Solution 5 - Visual Studio

you can to do this to add git bash (no install anything):

  1. Open tools

  2. Open terminal and push Add button

  3. Set this config (or your machine config) enter image description here

  4. Apply: set as default and Ok

  5. open one terminal View -> Terminal

enter image description here

  1. Add a new terminal (1) and select "git bash" (2) (this open a new tab 3)

enter image description here

can to close powershell terminal tab.

git bash tab open automatically next time that you open VS? Yes.

if you close Git bash tab? Open a new powershell terminal again and add Git bash terminal (step 5, 6)

Solution 6 - Visual Studio

I'll recommend you using GIT Tools for Visual Studio 2013 onwards

You can know its complete help information by visiting http://yysun.github.io/git-tools/#/

To install it go in Tools -> Extensions and Updates and type Git Tools. Download the plugin and install or you can simply visit visual studio market place https://marketplace.visualstudio.com/items?itemName=yysun.GitTools and click on download.

Snapshot of Git Tools

Once you have installed Git Tools extension and restarted all opened instances of visual studio

To Launch Git Bash:

  • Click on Git Tools -> Git Bash as shown below

enter image description here

enter image description here

However before performing these steps please ensure that you have git bash https://git-scm.com/downloads installed completed on your environment and most probably configured your logins if possible.

Solution 7 - Visual Studio

You can use posh-git in the Nuget Package Manager Console, which automatically switches to the location of the open solution.

Solution 8 - Visual Studio

Visual Studio 2019 integrated terminal solution calling bash directly is Ok, but doesn't provide developer environment. If you need it, use cmd.exe and start bash.exe from within. It can be automated via the same Tools/Options.../Environment/Terminal dialog:

  1. Shell location: C:\WINDOWS\system32\cmd.exe
  2. Arguments: /c ""%VSAPPIDDIR%\..\Tools\VsDevCmd.bat" -arch=x64 & <path\to\git-for-windows>\bin\bash.exe --login -i"

Notes:

  1. -arch=x64 selects development environment architecture
  2. --login -i e.g. sets correct "LANG" env var so that non-English filenames show correctly, also enables e.g. alias 'll' and filename colors
  3. /c instead of /k so that after you exit from bash, the command prompt exits as well

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndyView Question on Stackoverflow
Solution 1 - Visual StudioTarunView Answer on Stackoverflow
Solution 2 - Visual Studiotobi_sView Answer on Stackoverflow
Solution 3 - Visual StudioihorbondView Answer on Stackoverflow
Solution 4 - Visual StudiomanojldsView Answer on Stackoverflow
Solution 5 - Visual StudioMarbin274View Answer on Stackoverflow
Solution 6 - Visual Studiovibs2006View Answer on Stackoverflow
Solution 7 - Visual StudiodahlbykView Answer on Stackoverflow
Solution 8 - Visual StudioRoman OrekhovView Answer on Stackoverflow