Unable to modify git bash Windows shortcut
Under Windows 7 I'd like to change the settings for the Git Bash Here shell extension开发者_StackOverflow社区 command window, e.g. width, height and font. But when I do this, I get an error "Unable to modify the shortcut".
I can modify the shortcut for Git Bash in the Start menu by using "Run as administrator..." This works, but only for Bash windows opened from the Start menu. It doesn't work for the "Git Bash Here" shell extension and there's no "Run as administrator..." option on right-click context menu.
How do you do it?
2020 Update
KVN posted an update for Windows 10
This one seems to be simplier and works well for me on the latest Git.
- Right-click C:\Program Files\Git\git-bash.exe (Git for Windows)
- Click Properties
- Click the Compatibility tab in the Properties dialog
- Check the "Run This Program As An Administrator" check box
- Click OK button
Older
If you run git bash as administrator by right clicking on its icon and selecting "Run As Administrator" you will be able to change your settings and have them persist.
You can verify this by closing the admin session then reopening as a normal user.
I did this to set the defaults then just used git as a normal user from then on.
Edit: My answer is outdated if you're using the most recent msysgit version and sebastien.b posted the updated solution with - https://stackoverflow.com/a/7216120/104783
It states
The fix is to edit the
Git Bash.vbs
script and have it execute the link again, instead of sh.exe. Look for this line:
Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
and replace it with this line:
Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")
andrej351 also has a good reminder
Also, don't forget to select "Defaults" instead of "Properties" from the drop down menu in order to have the settings persisted
Unfortunately, the accepted answer offered by users sparks or bentayloruk doesn't work anymore (as of git 1.7.6 at least). The Git Bash.vbs
script triggered by "Git Bash Here" doesn't execute the Git Bash
shortcut any longer. It creates a temporary shortcut (.lnk) that executes the bin/sh.exe
executable in the Git install dir instead. Modifying the properties (fonts, color) of either that executable (sh.exe) or the Git Bash shortcut won't help.
The fix is to edit the Git Bash.vbs
script and have it execute the link again, instead of sh.exe. Look for this line:
Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
and replace it with this line:
Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")
Update: According to some comments and other answers, this answer is only relevant to older versions. Perhaps those prior to 1.7.6.
Full Instructions
You can modify the settings applied when using the Git Bash Here context menu by doing the following:
- Open the Git for Windows installation folder. e.g.
C:\Program Files (x86)\Git
. - Right click on the Git Bash shortcut file and select Run As Administrator.
- Click Yes if asked whether you want to give the Windows Command Processor permissions to modify the computer (otherwise your changes will not be persisted).
- Modify the properties as you wish (right click title bar and click properties) and then close the window.
Further Details
This works because clicking the Git Bash Here shell extension menu item runs the command wscript "C:\Program Files (x86)\Git\Git Bash.vbs" "%1"
. This is specified in the registry key HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
. This vbs file sets the current directory and then executes the Git Bash shortcut. Once you have changed the settings on this shortcut, they will always be used when this shortcut is run (regardless of being admin or not).
This one seems to be simplier and works well for me on the latest Git.
- Right-click C:\Program Files\Git\git-bash.exe (Git for Windows 2.x)
- Click Properties
- Click the Compatibility tab in the Properties dialog
- Check the "Run This Program As An Administrator" check box
- Click OK button
In case anyone comes here, as I did, looking for a way to have the Git Bash context menu run as admin (for any reason), thanks to the above, and here are the modified steps I needed to take to make this work:
- in Git directory (e.g. C:\Program Files (x86)\Git) create a shortcut called "Git Bash" with the target '"C:\Program Files (x86)\Git\bin\sh.exe" --login -i'
- Edit Git Bash.vbs as mentioned above, setting the target to "Git Bash.lnk"
- Remove the line 'link.Arguments = "--login -i"' from Git Bash.vbs
Thanks to all above for pushing me in the right direction.
PS, this is with Git-1.9.0-preview20140217 on Windows 7
You can edit the shell's context menu handlers directly in the Windows Registry. The one you're looking for is probably under one of these branches:
- HKCR\Directory\Shell\
- HKCR\Directory\ShellEx\ContextMenuHandlers\
- HKCR\Folder\Shell\
- HKCR\Folder\ShellEx\ContextMenuHandlers\
- HKCR\AllFilesystemObjects\shell\
- HKCR\AllFilesystemObjects\shellex\ContextMenuHandlers\
Here is a lengthy article explaining what you can do there. See the second half of this article for more tips on where to look.
try going to C:\Program Files (x86)\Git or wherever you installed git and edit the git bash shortcut, the size is in the layout tab
The instructions above did not work for me. I created a shortcut to cmd.exe in my taskbar, set it to run as Administrator, and told it to run git shell.
open %APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar
Right-click in the directory and choose New -> Shortcut
In the text field where it says "Type the location of the item", enter:
C:\Windows\System32\cmd.exe /c "%USERPROFILE%\Desktop\GIT Shell.lnk"
Choose a name for the shortcut and save.
Right-click the shortcut you just saved, click the Advanced... button, and then mark the checkbox for Run as Administrator.
I chose the default install location for the Git Shell shortcut in case it gets updated in a future release, but you can put it anywhere to make this work today - just be sure to update the command for your shortcut with the new location.
Now you can launch a command prompt as Administrator with all the Git Shell paths with one click in your taskbar.
Later versions, such as Git for Windows v2.7.2 (64 bit) don't use a VBS file so I modified the registry to run the shortcut via cmd.exe. It works, but you have to manually close the cmd window when it opens, which isn't too onerous.
The Registry key to change is
HKEY_CLASSES_ROOT / Directory / shell / git_shell / command
You will find default value should be something like:
"C:\Program Files\Git\git-bash.exe" "--cd=%1"
I changed it to
cmd.exe /k ""C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git\Git Bash.lnk" "--cd=%1""
The location of the lnk file may be different for you, and note also the double quoting needed around the command.
BTW - I use Git Bash for running my Ember CLI build and serve commands. Being able to run it with elevated permissions by setting the lnk to run as admin is useful because it improves performance significantly.
I had a similar problem with Git 2.8.2 (64 bit), which resulted in a .exe icon for the Git Bash (this might happen to Shell as well). Here's what I did:
- Open Git Bash
- Right-click on the opened taskbar icon
- Right-click on Git Bash
- Properties
- Check the Target and Start in fields if they are correct. Mine was targeting to Program Files (x86), but my Git is installed in Program Files
- Save and re-open the Git Bash.
Why this happened?
It was because I already had Git on my Windows, which was a 32 bits version, and then I - without knowing about the incompatibility - updated my Git to a newer version running in 64 bits.
Another way to resolve this would be by totally reinstalling it.
On windows 7, simply right click on the program, then choose properties
and enter a new shortcut.
You will need administrator rights.
You could try freewares like Default Programs Editor or Context Menu Editor, and see if that allows you:
- to edit properly the shortcut,
- or to define a new shortcut (which behaves like you want) and register that shortcut in the contextual menu.
Check out a modified "Git Bash.vbs" that uses the new method for UNC paths but the old method for local paths.
http://groups.google.com/group/msysgit/browse_thread/thread/0603d9565a988d48?pli=1
The problem I was having with Sebastien's solutions was that the bash path was always the parent of the folder I selected, which I found annoying.
This solution helped me to change font size:
Replace Target of Git Bash link with the following:
%ComSpec% /c "C:\Program Files (x86)\Git\bin\sh.exe" --login -i
Locate Git Bash link on the start menu, right-click and Run as Administrator.
Modify Properties of the opened console, not Defaults. Set whatever font you like. I prefer Consolas 28 since I'm pretty blind :)
You are done. You can close the console and run it again as regular user; the font size should be of your choice.
精彩评论