DEV Community

Cover image for How to integrate Git Bash with Visual Studio Code on Windows
Simon Massey
Simon Massey

Posted on • Updated on

How to integrate Git Bash with Visual Studio Code on Windows

Many clients will require me to work on a Windows laptop for access to their networks. Fortunately, I can change the settings within VS Code to use Git Bash as the built-in terminal. I can then get the same developer experience on a Windows laptop that I get at home on my mac.

First type "Ctrl+Shift+P" to open the command search and type/select "Open User Settings". If this display a settings search page you will need to hit the โ€{}โ€ at the top right to get to the raw JSON. Merge the following settings ensuring to use paths that match where you installed the "bash.exe" and "git.exe" binaries:

{
"terminal.integrated.shell.windows": "C:\\whereever\\Git-2.17.1\\bin\\bash.exe",
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1"
},
"terminal.integrated.shellArgs.windows": [
"-l"
],
// optional add git-path to use this version of git for built in visual studio model
"git.path": "C:\\whereever\\Git-2.17.1\\bin\\git.exe"
}
Enter fullscreen mode Exit fullscreen mode

Note that you don't have to use the last setting which is telling VS Code to use the git that came with Git Bash for its built-in git features.

The great thing about this approach is that you don't have to switch to a separate Bash Windows. The embedded terminal runs inside of VS Code and starts in the correct folder on disk. VS Code will filter the terminal output looking for file paths like ./server.js and it will turn them into hyperlinks. Ctrl+Click on them and it will open the file within the main editor panel! That is great when your build or unit tests you are running in the terminal throw an error logging the file to open.

Git Bash comes with all your favourite coreutils goodies like find, awk, sed, ssh, and more. You can also capture output to the windows clipboard with cat whatever | clip. You can read the windows clipboard with cat /dev/clipboard | awk -f mega_skills.awk. You can bash the heck out of any problem and be winning all day long.

Enjoy!

Top comments (1)

Collapse
 
charlesmendes1 profile image
CharlesMendes1

Very good explanation worked fine, thanks :D