integrating Git Bash with Visual Studio
Visual Studio 2019 after v16.6 comes with an integrated terminal similar to the one in Visual Studio Code. It also doesn't come with a preconfigured git bash, so in order to make it work you'll have to create the configuration.
- Open a terminal ("View -> Terminal") and click on the gear icon in the terminal window. Alternatively, go to "Tools -> Options" then "Environment -> Terminal"
- Click the Add button.
- 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
to get your default aliases and so on. The shell will be started in your solution's base directory. Note that the name in the list will not update before you close the dialog (as of VS 2022 17.3.1).
You should now be able to use bash in the integrated terminal via the default shortcut Ctrl + ` or via View -> Terminal in the menu.
As of VS 2022 17.3.1 there are two major bugs that I'm aware of:
- if you try to open your new bash, and you get a Powershell instead, the only way I'm aware of to fix that and to actually be able to open the bash is to delete the Powershell configuration that was used instead. If you need it, you should save its settings and restore them manually.
- if the Shell Location is set to a full path including the bash.exe executable, clicking the button labelled "..." on the right, which opens a file selection dialog, will make Visual Studio crash hard.
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)