Search code examples
macosgitsudo

Git commands require sudo on OSX


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?


Solution

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