Git: Open Git-Bash in specific directory

I am able to start git-bash via the Windows command prompt in several ways:

"C:\Program Files\Git\bin\sh.exe"
"C:\Program Files\Git\git-bash.exe"
"C:\Program Files\Git\usr\bin\mintty.exe"

I would like to start git-bash in a particular directory using such a call.


For context, I am doing this from within the SAS Enhanced Editor. The actual call is

%sysexec(start "" "C:\Program Files\Git\bin\sh.exe" && exit);

For those unfamiliar with SAS, %sysexec opens an instance of the Windows Command Prompt and issues whatever command is given as an argument. It works surprisingly well. However, I would like to be able to start the git-bash in a particular directory, not just home.

To this end, I can create an entry in .bashrc:

cd /c/new/starting/dir

The trouble with doing this, though, is whenever I open a git-bash, such as via the context menu in a particular folder, the default directory is that of .bashrc.

I see that there exist git-bash start options like --cd-to-home or --cd=<path> but I can't get them to work. For example,

"C:\Program Files\Git\bin\sh.exe" --cd-to-home
"C:\Program Files\Git\bin\sh.exe --cd-to-home"
"C:\Program Files\Git\git-bash.exe" --cd-to-home
"C:\Program Files\Git\git-bash.exe --cd-to-home"
etc.

Is it possible to start git-bash in a particular directory from Windows Command Prompt? If so, what's the proper syntax?

BONUS: Bonus points for doing it in 50 characters or less


"C:\Program Files\Git\git-bash.exe" --cd=c:\path\to\folder

One possible solution is to change the directory before opening git-bash. By default, git-bash opens in whatever the current directory is. To do this, put a cd call before the start,

cd C:\specific\dir\to\open && start "" "C:\Program Files\Git\bin\sh.exe"

Since this is being done in SAS, the specific directory can be stored in a macro variable. This guarantees the requirement of being within 50 characters (and therefore callable from a hotkey in the KEYS menu). Somewhere in your code you can assign the Git Working Directory,

%let gwd = C:\specific\dir\to\open;

The %sysexec call then looks like

%sysexec(cd &gwd. && start "" "C:\Program Files\Git\bin\sh.exe" && exit);

This works as follows. First, SAS will expand &gwd. It then opens a Windows Command Prompt. The cd changes directories to whatever &gwd. resolved to. Git-bash then opens in the current directory (which was changed to &gwd.). Finally, whenever git-bash closes, the exit command is given, closing the Windows Command Prompt session.

Unfortunately, it seems like the initial cd introduces just enough lag between the call and the opening of the git-bash to be annoying. I suspect that issuing a cd command within git-bash might be faster, but this approach does work.