How to add a context (aka right click) menu to the windows explorer that, when clicked, opens the git-bash console in the current explorer folder?
Step 1. On your desktop right click "New"->"Text Document" with name OpenGitBash.reg
Step 2. Right click the file and choose "Edit"
Step 3. Copy-paste the code below, save and close the file
Step 4. Execute the file by double clicking it
Note: You need administrator permission to write to the registry.
Windows Registry Editor Version 5.00
; Open files
; Default Git-Bash Location C:\Program Files\Git\git-bash.exe
[HKEY_CLASSES_ROOT\*\shell\Open Git Bash]
#="Open Git Bash"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_CLASSES_ROOT\*\shell\Open Git Bash\command]
#="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%1\""
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\shell\bash]
#="Open Git Bash"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
#="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%1\""
; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]
#="Open Git Bash"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
#="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%v.\""
And here is your result :
I had a similar issue and I did this.
Step 1 : Type "regedit" in start menu
Step 2 : Run the registry editor
Step 3 : Navigate to HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell. If you don't have the shell key, create one.
Step 4 : Right-click on "shell" and choose New > Key. name the Key "Bash"
Step 5 : Modify the value and set it to "open in Bash" This is the text that appears in the right click.
Step 6 : Create a new key under Bash and name it "command". Set the value of this key to your git-bash.exe path.
Close the registry editor.
You should now be able to see the option in right click menu in explorer
PS Git Bash by default picks up the current directory.
EDIT : If you want a one click approach, check Ozesh's solution below
The easiest way is to install the latest Git from here. And while installing, make sure you are enabling the option Windows Explorer Integration.
Once you are done, you will get those options in whenever you right click on any folder.
Hope it helps.
Here are the Registry exports (*.reg files) for Git GUI and Git Bash directly from the Windows installer —Git GUI:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui]
#="Git &GUI Here"
"Icon"="C:\\Program Files\\Git\\cmd\\git-gui.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui\command]
#="\"C:\\Program Files\\Git\\cmd\\git-gui.exe\" \"--working-dir\" \"%v.\""
Git bash:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell]
#="Git Ba&sh Here"
"Icon"="C:\\Program Files\\Git\\git-bash.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell\command]
#="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%v.\""
For detail about *.reg files, see “How to add, modify, or delete registry subkeys and values by using a .reg file” from Microsoft.
You can install git for windows or Github for windows , both give you the choice while installing to add this feature to your windows explorer. You can find it here:
Github for Windows
https://windows.github.com/
Git for Windows
http://git-scm.com/
As, #Shaswat Rungta said: "I think the question is more about how to add it after the installation is over."
On my PC(Windows 7) I think that the command "Git Bash here" disappeard after I installed Visual Studio 2017.
I fixt this by downloading and installing Git again.
NOTE: "When installing Git for Windows the context menu options are not 'on' by default. You will have to select them during the install." – #nbushnell
(I did this)
What worked for me was almost this, but with the following REGEDIT path:
HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Directory/background/shell and here I created the key Bash, with the value of what I want the display name to be, and then created another key under this named command with the value as the path to git-bash.exe
I'm on Windows 10 and have a fresh git install that didn't add this automatically for some reason (git version 2.12.0 64bit)
Had a similar issue in adding "Start Command Prompt with Ruby" to context menu as it involves passing parameters along with the patch of cmd. Followed a similar procedure as the solution above
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby]
#="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby\command]
#="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%1\"\""
[HKEY_CLASSES_ROOT\Directory\shell\bash]
#="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
#="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%1\"\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]
#="Cmd With Ruby"
"Icon"="C:\\Windows\\System32\\cmd.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
#="\"C:\\Windows\\System32\\cmd.exe\" \"/E:ON /K
\"C:\\Ruby25-x64\\bin\\setrbvars.cmd\"\" \"--cd=%v.\"\""
When you install git-scm found in "https://git-scm.com/downloads" uncheck the "Only show new options" located at the very bottom of the installation window
Make sure you check
Windows Explorer integration
Git Bash Here
Git GUI Here
Click Next and you're good to go!
Usually git bash here can be run only on directories so you have to go up a directory and right click on the previous directory then select git bash here (of course on Windows OS).
Note: context menu inside a directory does not have a git bash here option.
Another option but using PowerShell script.
This is basically a PowerShell script which does almost the same as this answer (it also adds icon).
Create file (addOpenGitBashHereContextMenu.ps1), paste in the code below and run it from PowerShell.
You probably need to change exePath to point to your git executable.
Also change contextMenuText if you want to change the text in context menu.
$exePath = $env:USERPROFILE + '\scoop\apps\git\current\git-bash.exe'
$contextMenuText = 'Open Git Bash Here'
$regEntryName = 'git_shell'
$regPathShell = 'HKCU:\SOFTWARE\Classes\Directory\Background\shell'
$regPathContextMenu = $regPathShell + '\' + $regEntryName
$regPathCommand = $regPathContextMenu + '\command'
$user = $env:UserName
echo "Setting '$contextMenuText' context menu..."
echo " User name: '$user'"
echo " Register path: '$regPathCommand'"
echo " Executable path: '$exePath'"
# Key: shell
If (-NOT (Test-Path $regPathShell)) {
New-Item -Path $regPathShell
}
# Key: regEntryName
If (-NOT (Test-Path $regPathContextMenu)) {
New-Item -Path $regPathContextMenu -Value $contextMenuText
# Add Icon to context menu
Set-ItemProperty -Path $regPathContextMenu -Name 'Icon' -Value $exePath
}
# Key: command
If (-NOT (Test-Path $regPathCommand)) {
New-Item -Path $regPathCommand -Value $exePath
}
Try updating your git. For window user you can update your git via cmd by simply writing the command- "git update-git-for-windows".
When done, you can simply right click inside a directory where you want to open the gitbash and check if its showing "Gitbash here" or not. If it's not showing anything, try to look for "Show more options" there and click on it. Now, you may able to see it.
I ran into this problem installing Git-2.38.1-64-bit on a new Windows 10 Pro corporate laptop.
I tried several things ... and considered one of the regedit scripts (the moral equivalent of "Nurse - chainsaw!")... but resolved the problem by simply uninstalling and reinstalling Git (as "Admin").
Specifically:
Control Panel > Programs/Features > Uninstall Git
Reboot Windows
Reinstall Git-2.38.1-64-bit as "Admin"
Carefull check all the options, especially:
"Windows Explorer Integration: Git Bash Here, Git GUI Here
<= These are checked by default ... and I'm sure they were both "Y" on the initial install
I copied my .gitconfig ("C:\Users\USERNAME.gitconfig") from another PC
<= I don't believe this was "essential" ...but I thought I'd mention it...
Browse to a local Git repo and verify the Git context menus work
<= Success after reinstall!
I updated my git and I marked the option of "Git Bash Here"
I have already too many programs that want a spot on my PATH list. Rather than pollute my PATH list, I choose instead to add a symbolic link, from an elevated command prompt, like so.
mklink C:\bin\git-bash.exe "C:\Program Files\Git\git-bash.exe"
While there are exceptions, this works in the majority of cases, including, among others, the 7-zip CLI, selected SysInternals command line tools, the NuGet CLI, and many others.
As a bonus, having the Git Bash command line interface so readily accessible makes activating it from an open command prompt window trivial. With this improvement, I can probably live without yet another item on my context menu for directories.
In addition to the answers with the theory and the minimal examples see the example of the .reg file for Git (and not only, with the instruction) with user-friendly names, shortcut keys (& in a user-friendly name) and icons in the "win-registry-snippets" repository
Do Nothing.
Just open your git bash terminal and type in:
git update-git-for-windows
Once update is completed, this will automatically add "Git Bash here" into your context menu.
Refer this: https://stackoverflow.com/a/65467670
You can install TortoiseGit for Windows and include integration in context menu.
I consider it the best tool to work with Git on Windows.
Add the gitpath to the Environment-path variable (e.g. C:\Program Files\Git\cmd) by which you can access git from any folder using command line.
Use Shift + F10 to open the menu of options which appear when right clicked, and then click s to git bash here.
Related
I have installed git via Scoop on Windows 10 x64.
Using the detailed instruction from this answer I created my own reg script, to add a "Open Git Bash" command in the context menu of Windows Explorer, for my own user:
Windows Registry Editor Version 5.00
[HKEY_USERS\user-sid\Software\Classes\*\shell\Open Git Bash]
#="Open Git Bash"
"Icon"="C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe"
[HKEY_USERS\user-sid\Software\Classes\*\shell\Open Git Bash\command]
#="\"C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe\" \"--cd=%1\""
; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_USERS\user-sid\Software\Classes\Directory\shell\bash]
#="Open Git Bash"
"Icon"="C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe"
[HKEY_USERS\user-sid\Software\Classes\Directory\shell\bash\command]
#="\"C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe\" \"--cd=%1\""
; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_USERS\user-sid\Software\Classes\Directory\Background\shell\bash]
#="Open Git Bash"
"Icon"="C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe"
[HKEY_USERS\user-sid\Software\Classes\Directory\Background\shell\bash\command]
#="\"C:\\Users\\fritzmg\\scoop\\shims\\git-bash.exe\" \"--cd=%v.\""
However, there are two problems with this:
1. Icon does not work
The icon within the context menu does not work:
May be this is more of a scoop issue. I am not sure how scoop creates those shims.
2. Two git bash windows open
When I actually use the context menu option, two git bash windows open:
One with the actual git bash, and one that just says "git-bash.exe". Closing either window closes both windows.
Of course I'd like to have it as if I had downloaded and installed git directly from https://git-scm.com/download/win . May be someone has any insights on how to alleviate those issues?
The shim.exe doesn't have an icon, so it can't be displayed.
In this case, it's recommended to use the current version path. (e.g. ~\scoop\apps\git\current\git-bash.exe)
Change the icon path to:
[HKEY_USERS\user-sid\Software\Classes\Directory\Background\shell\bash]
#="Open Git Bash"
"Icon"="C:\\Users\\fritzmg\\scoop\\apps\\git\\current\\git-bash.exe"
Right clicking a folder in windows opens the submenu of a windows right click. Where you have the basic OS operations like "Open", "Edit", "rename" etc.
If git is installed you also have the option to "git bash here". This command should open the terminal/cmd and directly point to the right-clicked folder. But it's always openening in the root system folder.
tl;dr; clicking "git bash here" opens the system root folder instead of the right-clicked one
The way I solve my own problem is to uninstall Git, and delete .bashrc manually (cause uninstall Git doesn't remove that file), and install Git again. And the terminal open correctly in my working folder rather than root system folder. Thanks to Todd.
As one of the comments suggest, the .bashrc file is the one to "blame".
Deleting it would solve the issue.
However, it contains valuable declarations. So "don't throw the baby out with the bathwater": a minor edit would do the trick:
Open Git Bash window. While the bash is active, enter the following:
vim ~/.bashrc
In my case, the bottom line (scroll using arrows) was:
cd /c
Just delete it (press twice on d), and then quit with saving, by pressing :, and then wqEnter.
That's it! The next time you open Git Bash Here - you should see the shell active on the relevant folder.
I have right click integration with CMDer to pop up a console, but it's defaulting to my user directory instead of the directory I performed the right click in. If you press Win+R and run cmd, or hold shift and right click to open a command prompt from the context menu; the command prompt opens up at that location. I've been able to get CMDer/ConEmu to pick up on that use it, however it seems to be a plain command prompt, no additional features supported.
Ideally I could elevate to run as admin, have tried -new_console:a in the integration settings menu with no luck.
You can go to Settings > Integration and set this in command field (upper section).
{bash} -cur_console:n:d:"%V"
%V is used to pass the current directory you are in.
After that you just need to hit the Register button in the upper section.
AFAIK CMDer forced your active directory to the user profile. Bare ConEmu do not do that. That's because cmder initialization scripts.
However without precise description hire do you set up your menu item (screenshot) and example of the directory you are trying it's impossible to be sure.
I solved the problem modifying the command syntax in registry. For example, it would look like that for the directories:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Cmder]
#="Cmder Here"
"Icon"="C:\\tools\\cmder\\icons\\cmder.ico"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\Cmder\command]
#="\"C:\\tools\\cmder\\Cmder.exe\" \"%V\""
You can fix this for drives as well. Don't forget about Background section so you can use the menu option from blank space in Explorer.
To run the shell in elevated mode you may add "*" (asterisk) before the command in tasks setup, like this:
Here is the full .reg file employing the fix. Just replace the path with your cmder installation and enjoy.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Drive\Background\shell\Cmder]
#="Cmder Here"
"Icon"="C:\\tools\\cmder\\icons\\cmder.ico"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Drive\Background\shell\Cmder\command]
#="\"C:\\tools\\cmder\\Cmder.exe\" \"%V\""
[HKEY_CLASSES_ROOT\Drive\shell\Cmder]
#="Cmder Here"
"Icon"="C:\\tools\\cmder\\icons\\cmder.ico"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Drive\shell\Cmder\command]
#="\"C:\\tools\\cmder\\Cmder.exe\" \"%V\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\Cmder]
#="Cmder Here"
"Icon"="C:\\tools\\cmder\\icons\\cmder.ico"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\Cmder\command]
#="\"C:\\tools\\cmder\\Cmder.exe\" \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\Cmder]
#="Cmder Here"
"Icon"="C:\\tools\\cmder\\icons\\cmder.ico"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\Cmder\command]
#="\"C:\\tools\\cmder\\Cmder.exe\" \"%V\""
P.S. It just struck me that %CMDER_ROOT env var may be used instead of the absolute path.
In my case worked by passing in the command arguments: /START "%folder%"
In the newer versions of cmder registering the right-click is enough.
Open the command prompt where cmder.exe exists. Then enter:
.\cmder.exe /REGISTER USER
In the newer version just go to Settings -> Integration -> Register -> Save Settings.
Note click the first register button of the upper section and then save the setting and its done, go to folder where you want to open the application press and hold shift key and right click and will appear ComEmu Here in dialog box.
It's for the latest versions.
In Windows I can run "Git Bash Here" in the current directory by opening right click menu.
I want to place gitbashhere.bat in default path for commands to have got easy access from standard cmd window.
The sh.exe --login -i command only opens git bash in sh.exe's directory instead of the current directory.
How do I check what command is bound to "Git Bash Here"?
How do I check what command is bound to "Git Bash Here"?
Open the Registry Editor using regedt32 or regedit.
Menu "Edit" > "Find" > "Find what" and enter "git_shell"
Examine the returned Registry entries.
One will be:
HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
With the value:
"C:\Windows\SysWOW64\cmd.exe" /c "pushd "%1" && "C:\git_install_dir\bin\sh.exe" --login -i"
where git_install_dir is the directory where you have installed git.
You can see it runs something similar to the following command:
pushd "%1" && "C:\git_install_dir\bin\sh.exe" --login -i
Another way to see how a specific program was started is to launch Process Explorer, look for the process in the list of processes (for git this would be "git-bash.exe") and double-click on the process to open the properties.
On the 'Image' tab there's a text field that yields the command line of the process:
That is a windows shell thing. It depends on the git GUI toolkit that you've installed. For tortoiseGit, there's a setting hidden somewhere in the configuration menu. If that doesn't suit you: It's free and open software, so fix that :)
Sorry if this has been asked before, I've been looking around and it's hard to find what I want.
I know how to add a context menu item to a folder like so:
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Open Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%1\"\""
but, that only works for right clicking on a folder. I want it so that you can be inside the folder, and click a blank part of that folder and get the context menu item as well. I also tried HKEY_CLASSES_ROOT\Directory\shell as well, but it does the same.
I figured out the answer. The folder is actually Directory\Background, you have to add the empty string value of NoWorkingDirectory into it, and the %1 in the command becomes a %V
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2]
#="Open Console2 Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\console2\command]
#="C:\\Program Files\\Console\\console.exe -d \"\"%V\"\""
Source:
saviert's comment at http://www.howtogeek.com/howto/windows-vista/make-command-prompt-here-always-display-for-folders-in-windows-vista#comment-57856
Console2 rocks. I added an 'Cmd here (Console2)' item to my explorer context menu.
Save the text below in a file named open-console2.reg then open it to import it to the Windows registry.
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2]
#="Cmd here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -d \"%V\"\\"
Bonus 'bash here' item (assumes you have a Console2 tab named 'bash').
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash]
#="Bash here (Console2)"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\console2_bash\command]
#="\"C:\\Program Files (x86)\\Console2\\Console.exe\" -t Bash -d \"%V\"\\"
I think the relevant part of the TortoiseSVN installer is here. Perhaps you can figure out all the necessary registry keys from that.
None of the above worked for me.
But this does (tested on Windows 7 Pro x64):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Open console here\command]
#="u:\\users\\dave\\data\\bin\\Console2\\Console.exe cmd -r \"/k pushd %L\""
Replace the path with the path to your copy of console.exe (of course).
#Ben Voigt mentioned TortoiseSVN, you can also see WinMerge shell extension source code, or at last: create your own extension from scratch; I wanted to do something like this for XP but I have lots of other stuff to do now.
As a workaround, you can just open a folder in XP, and then select View->Explorer Bar->Folders, to have folder tree on left, and then you're able to right-click the folder (active folder gets hightlighted automatically).
Here it is if you prefer MinGW.
#!/bin/sh
reg add 'HKCR\Directory\Background\shell\sh' -d 'Open Bash window here'
reg add 'HKCR\Directory\Background\shell\sh\command' \
-d 'C:\MinGW\msys\1.0\bin\sh.exe -l'
printf 'cd -' >> ~/.profile
superuser.com/a/387273
According to my personal experience of Windows XP (SP3), you can open Console2 inside the current directory with a context menu entry using the following .reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\console2]
#="Console2 Here"
[HKEY_CLASSES_ROOT\Folder\shell\console2\command]
#="C:\Program Files\Console\console.exe -d \"%1\""
If you look at the key value inside regedit.exe , you should see:
C:\Program Files\Console\console.exe -d "%1"
instead of:
C:\Program Files\Console\console.exe -d ""%1""
The latter would open Console2 in its default start directory.
This can be achieved in XP as well.
First open the program Run with the Windows key + R,
and type Regedit in the textbox.
Press Enter.
In the Registry open the Key : HKEY_CLASSES_ROOT
and then : *
You will now see a key called : shell
Rightclick on shell and point to New.
Click in de menu on Key.
Now type a name of your choice which you want to appear in the Rightclick menu.
Rightclick on the name you chose, again point to New and click Key.
Now type : command
Click on command and in the right pane of the Registry doubleclick on (Default).
In the textbox Value Data, type the path to an application you want to open via the chosen name in the rightclick menu.
For example : "C:\Program Files\CCleaner\CCleaner.exe"
Then type after the path : %1,
and leave a space between the end of the path and %1
It should look like this :
"C:\Program Files\CCleaner\CCleaner.exe" %1
This way, it's possible to open any kind of application you want.
There's only one drawback,
you have to rightclick another file to see the chosen name with which you can open the application.
When you rightclick a folder this will not work.