Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commands require sudo on OSX

Tags:

git

macos

sudo

I've moved back from my work MBP to my home MBP. The work one allowed to run git commands without the need for sudo. But I'm finding this is a requirement on my home machine.

I would prefer to be able to run git commands without sudo.

I looked at the git commands in /usr/bin, and they all have rwxr-xr-x (755), and are owned by root and group wheel. I suppose I could change this to rwxrwxrwx (777), but I'm wondering if there's a better way. I'm thinking of adding my user to the wheel group; but would there be other side effects?

like image 883
NotoriousWebmaster Avatar asked Mar 03 '15 13:03

NotoriousWebmaster


People also ask

Should I use sudo with Git?

The Git command uses credentials and configuration stored in the current user's home directory; when you run as sudo , this code is going to be looking at the root home directory, not your home directory and thus miss this context. In most cases, it should not be necessary to use sudo .

How do I clone a sudo in git?

You will need to do two things: Put the username in your URL: ssh://[email protected]/soft.git. Make your SSH key available to the root user, because it will look under /root/. ssh instead of /home/user/.


2 Answers

The permission on the git executable are fine; there is no reason you should need to change that, or change your group.

It's more likely that the permissions on your Git checkout are wrong. If you accidentally checked it out with something like sudo git clone ssh://user@host/project.git, or at some point you performed some kind of operation in the repository that caused some files to be owned by root, git running under your account won't be able to write to those files.

Most likely, what you need to do is chown -R <user> myproject in order to make your project owned by your own user account, rather than root.

like image 59
Brian Campbell Avatar answered Oct 09 '22 21:10

Brian Campbell


If you were prompted like this:

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

And then you ran:

sudo git init .

After updating xcode license. Just remove the init and re-init w/o sudo

sudo rm -rf .git
git init .

This fixed my issue.

like image 33
Gregism Avatar answered Oct 09 '22 20:10

Gregism