Bare Git Repositories

From this site. One of the best pages I’ve seen about how to do this.

1. On the remote machine (where you want the bare repo):

sudo su - git
cd /usr/local/git_root/

2. Now create the home of the new bare repo:

mkdir foo-project.git
cd foo-project.git/
git --bare init

3. Set up some git permissions which make sense for a shared git repo:

git config core.sharedrepository 1
git config receive.denyNonFastforwards true
find objects refs -type d -exec chmod 02770 {} \;

core.sharedrepository 1 instructs git to keep everything group-readable and writable. receive.denyNonFastforwards true enforces no merges on push. The merges have to be done BEFORE you push. This keeps the repo users from polluting the server. The find just makes sure that the objects and refs dirs (and all their files) are set-gid.

note the original web page did not also have refs but I found that I needed it or the pushes would fail.

note one of the comments on the source page suggests that git init –bare –shared=group will do the same. I haven’t tried it.

4. On your local machine, set up a remote:

git remote add origin ssh://

5. Push the data from the local machine to the new shared repo:

git push -u origin master

Now, to ensure that your local branch is tracking when you do a fetch, you need to use -f option to force a new local branch to be created even though it already exists. (I have not had to do this, but it was on the source web page and I’m keeping it here in case there is trouble):

#Switch to origin/master so you don't get any error about "fatal: Cannot force update the current branch." 
git checkout origin/master
#Create the local "master" branch that is tracking the "origin/master" branch
git branch -f master origin/master
#Switch back to your "master" branch
git checkout master
Add picture from clipboard (Maximum size: 1 GB)