1

I am trying to add an extra remote to an existing git project so I can push code to a secondary bitbucket repository using the git remote add user2 git@bitbucket.org:... , but I am getting the following error:

error: could not lock config file .git/config: Permission denied

It is an old project so I am not sure how it was originally setup, but it does seem like it may have been installed as root.

I tried checking the file permissions for .git and .git/config and I can see it belongs to www-data. My current user is part of the www-data group, but I still get the same error.

I also checked for .git/config.lock file just in case it was blocking but there isn't one.

I am not a fan of using sudo with .git, so I am wondering if someone can give me some best practice advice on how deal with this

Finglish
  • 9,692
  • 14
  • 70
  • 114

2 Answers2

1

Making everything owned by a group is the way to go, but you must make sure it everything has both group write permissions and every file is in the www-data group recursively:

  sudo chown -R :www-data /path/to/git/repo
  sudo chmod -R g+w /path/to/git/repo

Then run your git commands.

Ray
  • 40,256
  • 21
  • 101
  • 138
0

You should not have to use sudo with git if your permissions are set up correctly.

This sounds like a basic permissions issue. You found you're part of the group, but you also need the file to have group rw permissions if you are banking on access via group perms, e.g. chmod g+rw .git/config. Either that or you need to be the owner of the files in question, also with rw.

Since you mention www-data as the group, it makes me wonder if you're on a server. If you're using a server OS such as CentOS, you likely have SELinux running, in which case that's another layer of permissions you need to deal with. Use ls -alZ to see SELinux perms if present.

tniles
  • 329
  • 1
  • 11