5

I setup git on an ubuntu server and I was pushing the local repo to the server and getting the errors below. When I change the permissions of the two folders it works. I just want to understand why when I setup git init --bare it doesn't just work with the permissions it creates. Also is 777 the best permissions to have for these folders? Is there a more legit way of fixing this?

The first error:

error: insufficient permission for adding an object to repository database ./objects

The first solution:

sudo chmod 777 objects/

The second error:

fatal: Unable to create '/srv/git/example.com.git/refs/heads/master.lock': Permission denied

The second solution:

sudo chmod 777 refs/heads/
Rodrigo Flores
  • 2,411
  • 18
  • 17
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • Consider using gitolite. It takes the hassle out of stuff like this – Andrew Walker Jun 23 '12 at 03:41
  • Did you init the repo as another user? `git init` will set things up so that they can be accessed by the user that init'ed the repo. As for another user, they'd normally just clone the repo, which would init them their own copy (and thus make it usable by them). – cHao Jun 23 '12 at 04:25

2 Answers2

11

Running

$ git init --shared=0777 --bare

should do what you want.

From http://git-scm.com/docs/git-init

Alternatively, you could set up an openssh server on your server and have users access this repository through ssh.

Rodrigo Flores
  • 2,411
  • 18
  • 17
Kent
  • 464
  • 4
  • 5
4

It is a very bad sign that you're want to use 777 permissions. You're doing something wrong.

First and foremost, as already suggested, consider using gitolite.

If you're not likely to have more than one or two repos for one or two contributors, gitolite may seem an overhead, especially if you're never worked with it before. (But I still recommend using it.)

Before I came to using gitolite, I used this script to create my shared git repos. How it works:

  1. All Git repo users (of a particular repo) should be in a same group.
  2. Directory of the repo should be owned by this group.
  3. Sticky group bit should be set on this directory (make sure not to set it on files), so group would be preserved when users commit stuff.
  4. Git repo should be initialized with --shared option, to give it group write permissions.
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160