70

Under Windows 7 I'd like to change the settings for the Git Bash Here shell extension 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?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
netgirlk
  • 725
  • 1
  • 6
  • 7

14 Answers14

86

2020 Update

KVN posted an update for Windows 10

This one seems to be simplier and works well for me on the latest Git.

  1. Right-click C:\Program Files\Git\git-bash.exe (Git for Windows)
  2. Click Properties
  3. Click the Compatibility tab in the Properties dialog
  4. Check the "Run This Program As An Administrator" check box
  5. 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

sclarson
  • 4,362
  • 3
  • 32
  • 44
  • this worked but i had to run the Bash Shortcut icon as administrator once and it persisted the settings. – netgirlk Aug 17 '10 at 14:54
  • Can you tell me how to change the settings once I'm administrator? I'd like to change the font. – Franz Dec 09 '10 at 10:26
  • 1
    Right click on the top bar of the application and choose properties. Then there is a fonts tab. You may also want to consider a new console like http://sourceforge.net/projects/console/ – sclarson Dec 15 '10 at 17:14
29

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")
sebastien.b
  • 1,049
  • 1
  • 14
  • 12
  • ^^This should be at the top. Also, don't forget to select "Defaults" instead of "Properties" from the drop down menu in order to have the settings persisted. – andrej351 Sep 08 '11 at 06:00
  • Sweet! Have been looking for this for a long time. I almost didn't read beyod the accepted answer. – Rudie Jan 07 '12 at 17:15
  • 2
    Editing `Git Bash.vbs` this way in order to make changes to the console window's properties persistent was necessary starting with Git-1.7.6-preview20110708 but is not longer required anymore with Git-1.7.7-preview20111014 or newer. – sschuberth Jun 30 '12 at 17:33
  • 9
    I think there are a TON of assumptions here... first of which... where would I find ```Git Bash.vbs```. I see no explanation for this and isn't very helpful if I have no clue where this is. I did a search in the directory which git was installed to and turned up no ```bash.vbs``` and the only files with the word "bash" are .exe files. Can we put more information in this answer? Where would I find this file that must be edited? Also, it says it doesn't use this but creates a shortcut? Where do I find this shortcut? – Goblinlord Oct 11 '16 at 05:54
  • @Goblinlord and at least 8 other people who upvoted the comment: I have some help for you and anyone who might come after. From the start menu search, type "Git Bash". (N.B. "Git Bash Here" should only come up when you right-click in a directory). Right click on "Git Bash" and press "Open File Location". For me, this brings up a Start Menu folder with a "Git Bash" shortcut. Right-click on that and go to "Properties". Pull up the "Shortcut" tab, and that will give you the *git installation directory* as "Target". (Note you could click on "Advanced" & check the "Run as Administrator" box.) – bballdave025 May 01 '21 at 00:23
  • Go to the *git installation directory* (path only to '\Git\' ).A "Git Bash" shortcut may be there. If not,the Start Menu shortcut likely won't work for the task.I opened my non-administrator Git Bash terminal, then ran `{find /c/ -iname 'git bash.lnk' 3>&2 2>&1 1>&3 | grep -iv 'permission denied\|file not found' >&3;} 3>&2 2>&1`, cf [this comment](https://stackoverflow.com/questions/762348/how-can-i-exclude-all-permission-denied-messages-from-find#comment69853411_40336333). My non-Start-Menu shortcut had a convoluted path that ended with `ImplicitAppShortcuts/58dc9c9c4a87b968/Git Bash.lnk`. – bballdave025 May 01 '21 at 01:04
7

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:

  1. Open the Git for Windows installation folder. e.g. C:\Program Files (x86)\Git.
  2. Right click on the Git Bash shortcut file and select Run As Administrator.
  3. 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).
  4. 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).

bentayloruk
  • 4,060
  • 29
  • 31
5

This one seems to be simplier and works well for me on the latest Git.

  1. Right-click C:\Program Files\Git\git-bash.exe (Git for Windows 2.x)
  2. Click Properties
  3. Click the Compatibility tab in the Properties dialog
  4. Check the "Run This Program As An Administrator" check box
  5. Click OK button
KVN
  • 863
  • 1
  • 17
  • 35
4

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:

  1. 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'
  2. Edit Git Bash.vbs as mentioned above, setting the target to "Git Bash.lnk"
  3. 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

3

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.

ewall
  • 27,179
  • 15
  • 70
  • 84
1

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

leegeorg07
  • 261
  • 2
  • 2
1

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.

  1. open %APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

  2. Right-click in the directory and choose New -> Shortcut

  3. 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"

  4. Choose a name for the shortcut and save.

  5. 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.

Community
  • 1
  • 1
1

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.

Glenn Lawrence
  • 2,844
  • 1
  • 32
  • 38
  • 1
    Excellent. The only answer to go to the root of the problem (and give not only a solution but an example use case) for versions after 1.7.6. I've added a comment after the answer from @sebastien.b with some help for finding the shortcut (`lnk`) file. – bballdave025 May 01 '21 at 01:25
1

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:

  1. Open Git Bash
  2. Right-click on the opened taskbar icon
  3. Right-click on Git Bash
  4. Properties
  5. 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
  6. 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.

felippe
  • 493
  • 6
  • 7
1

On windows 7, simply right click on the program, then choose properties and enter a new shortcut. You will need administrator rights.

ecstrema
  • 543
  • 1
  • 5
  • 20
0

This solution helped me to change font size:

  1. Replace Target of Git Bash link with the following:

    %ComSpec% /c "C:\Program Files (x86)\Git\bin\sh.exe" --login -i

  2. Locate Git Bash link on the start menu, right-click and Run as Administrator.

  3. Modify Properties of the opened console, not Defaults. Set whatever font you like. I prefer Consolas 28 since I'm pretty blind :)

  4. You are done. You can close the console and run it again as regular user; the font size should be of your choice.

Igl3
  • 4,900
  • 5
  • 35
  • 69
Vitamin C
  • 871
  • 6
  • 2
0

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.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Thanks, but surely there's a way to do this without installing 3rd party software?!?! I know it's possible because my colleague has done it, but can't remember how!!! :-)) – netgirlk Apr 12 '10 at 11:09
0

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.

Jimmy Bosse
  • 1,344
  • 1
  • 12
  • 24