11

If we open msysgit as administrator, we can use it as if we were root. However, it is often easier to open without administrator privileges. For example, for administrator privileges, you often have to go to Windows Explorer, the Start menu/screen, etc., and you can't do this from the taskbar. Sometimes, I'm too lazy to do all this, but I want to gain administrator privileges while in Bash. Is there a sudo- or su-like command or script, etc., for Git Bash? Going into cmd.exe, PowerShell, etc., then doing something like runas would work, if there's nothing else.

trysis
  • 8,086
  • 17
  • 51
  • 80

1 Answers1

22

you can't do it from the taskbar

You could though: press ctrl+shift while you are clicking on the icon, and it will open as Administrator.

Note: msysgit is based on msys, which doesn't include any sudo-like command.

As commented by aheryan, you can type ctrl+shift+enter when you're searching for Git Bash from the Start Menu: that will also launch it as Administrator.


June 2021: Svens suggests in the comments another approach:

You can make the taskbar symbol always open gitBash as admin automatically:

  • right-click it,
  • then right-click on "git Bash",
  • then open "properties"
  • Button "Advanced" opens another dialog with a checkbox for "Run ad administrator".

If you activate this, the "shortcut" in your taskbar will always open with admin permissions (the exact same works with Desktop icons and any other shortcuts).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, that at least makes it easier. For all my time with Windows, I'm still learning new things all the time. – trysis Apr 01 '14 at 07:13
  • 1
    This solution saves my day! Thank you! An alternative is when you're searching for **Git Bash** from the Start Menu, hitting ctrl+shift+enter will also launch it as Administrator. – stephen Nov 06 '18 at 11:17
  • @aheryan Thank you. I have included your comment in the answer for more visibility. – VonC Nov 06 '18 at 14:33
  • Old post, but another option: You can make the taskbar symbol always open gitBash as admin automatically: right-click it, then right-click on "git Bash", then open "properties". Button "Advanced" opens another dialog with a checkbox for "Run ad administrator". If you activate this, the "shortcut" in your taskbar will always open with admin permissions (the exact same works with Desktop icons and any other shortcuts). – SvenS Jun 08 '21 at 06:58
  • 1
    @SvenS Interesting idea, thank you for this feedback. I have included your comment in the answer for more visibility. – VonC Jun 08 '21 at 08:35
  • can it be done via powershell? – openCivilisation Apr 28 '22 at 12:34
  • @openCivilisation 8 years later, I do not know for sure: you can open a powershell as admin with the ctrl+shift option mentioned in the answer. – VonC Apr 28 '22 at 14:22