How to open Visual Studio Code from git bash in Windows

tools

How to open Visual Studio Code from git bash in Windows

I wanted to be able to open Visual Studio Code from my current folder while in git bash on Windows. I tried a couple different methods which included calling Update.exe, which is what my VS Code shortcut calls. It looks like this

C:\Users\username\AppData\Local\Code\Update.exe --processStart Code.exe

But I was having issues passing the options I wanted to this .exe. There is also the batch file that is executed when you run code on the command line. It can be found here

C:\Users\username\AppData\Local\Code\bin\code.cmd

This .cmd should be in your PATH if you want to run it from the command line. Its contents are the following

@echo off
set VSCODE_CWD=%cd%
"%~dp0\..\Update.exe" --processStart Code.exe -a="%*"

Trying to translate this batch script to bash was looking to be more of a headache than I wanted to deal with. I then thought, “why don’t I call the batch script, which does everything I want already, from git bash?” So I created an alias in my .bashrc for the batch file.

alias code='cmd //C code $*'

Now I can use the VS Code command line options from bash, for example

> code . --new-window

which opens the current folder in a new Code window.