Skip to content

Instantly share code, notes, and snippets.

@bakana808
Last active March 15, 2022 06:38
Show Gist options
  • Save bakana808/a9e07c1f0bfe193f47fe to your computer and use it in GitHub Desktop.
Save bakana808/a9e07c1f0bfe193f47fe to your computer and use it in GitHub Desktop.
GitHub For Windows "Open with Git Bash" Context Menu Script

GitHub For Windows "Open with Git Bash" Context Menu Script

Here's instructions to add a "Open with Git Bash" option to your context menu using the Git Bash that comes with GitHub for Windows.

Here's the registry script to add the option in. Because the installation paths for GitHub for Windows varies from user to user, I will go over which lines to change so that this script works for you.

Copy this script into your favorite text editor.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\directory\shell\git_bash]
@="Open with Git Ba&sh"
; optional: set "Icon" key to change the icon of the option

[HKEY_CLASSES_ROOT\directory\shell\git_bash\command]
@="\"C:\\WINDOWS\\SysWOW64\\wscript.exe\" \"C:\\Users\\<username>\\AppData\\Local\\GitHub\\PortableGit_<guid>\\Git Bash.vbs\" \"%1\""

The line under [HKEY_CLASSES_ROOT\directory\shell\git_bash] sets the text of the option that will show in your context menu.

image of context menu

Feel free to change the text between the quotations. The & tells Windows that the next character is the shortcut key for it.

The line under [HKEY_CLASSES_ROOT\directory\shell\git_bash\command] sets the command that the option will run.

Before changing this line, note that the command needs to be surrounded by double quotes, and all slashes and double quotes inside need to be escaped with \\.

The three parts of the command are:

  1. the full path to wscript.exe.
  2. the full path to PortableGit's git.exe that GitHub For Windows installs. (ex. AppData/Local/GitHub/PortableGit_<guid>/bin/git.exe)
  3. "%1", which will be replaced with the path to the folder you right-clicked on when the command runs.

In my case, the resulting command that you want to run is:

C:\WINDOWS\SysWOW64\\wscript.exe C:\Users\<username>\AppData\Local\GitHub\PortableGit_<guid>\Git Bash.vbs "%1"

Now you have to surround it in quotes and escape all the slashes and double quotes to copy it into the script:

@="\"C:\\WINDOWS\\SysWOW64\\wscript.exe\" \"C:\\Users\\<username>\\AppData\\Local\\GitHub\\PortableGit_<guid>\\Git Bash.vbs\" \"%1\""

Optional: How to Use GitHub For Windows's Icon

  1. Run GitHub for Windows.
  2. While GitHub for Windows is running, open the Task Manager (ctrl+shift+esc)
  3. Find GitHub.exe under Details, right click it, and click Open file location.
  4. Shift+right-click GitHub.exe in the explorer, and click Copy as Path.
  5. In the registry script, under @="Open with Git Ba&sh", add a new line.

Type "Icon"= and paste the path you copied. Be sure to close it in double quotes and escape all the slashes. My example:

"Icon"="C:\\Users\\<username>\\AppData\\Local\\Apps\\2.0\\45TL3GP7.TQE\\WT1D0ML9.C6O\\gith..tion_317444273a93ac29_0002.000d_6a9b565322d28a14\\GitHub.exe"

After that is all done, save the script (as a .reg) and run it.

How to Remove "Open with Git Bash" from the Context Menu

If you want to remove this option from context menu at any time, run this script.

Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\directory\shell\git_bash]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment