integrating Git Bash with Visual Studio
Visual StudioGitVisual 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.
- Go to "Tools -> Options" then "Environment -> Terminal"
- Before changing anything, click the Add button.
- 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.
- 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:
- Use MoveUp to move 'Git Bash' to the 1st position.
- Go to Tools -> Options -> Environment -> Keyboard and search for Tools.ExternalCommand1
- 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):
-
Open tools
-
Open terminal and push Add button
-
Apply: set as default and Ok
-
open one terminal View -> Terminal
- Add a new terminal (
1
) and select "git bash" (2
) (this open a new tab3
)
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.
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
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:
- Shell location:
C:\WINDOWS\system32\cmd.exe
- Arguments:
/c ""%VSAPPIDDIR%\..\Tools\VsDevCmd.bat" -arch=x64 & <path\to\git-for-windows>\bin\bash.exe --login -i"
Notes:
-arch=x64
selects development environment architecture--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/c
instead of/k
so that after youexit
frombash
, the command prompt exits as well