Setting up such a repository in git involves a few simple steps. For simplicity's sake, I will assume that:
- you have sorted out the UNIX permissions issues (e.g. putting all developers in a common group and adjusting permissions on the appropriate directories)
- and that the repository is located on the same machine (replace /tmp/myrepo.git by ssh://hostname/repo.git if you need to access a different machine).
A bare repository in git is one that doesn't have an associated code checkout. It's essentially like the .git subdirectory of a normal repository.mkdir /tmp/myrepo.git
cd /tmp/myrepo.git
git --bare init --shared
Then you need to create a normal repository from which you will push to the central one you just created:
You can't push yet because this local repository is completely empty (hence there is nothing to push). So let's create an initial commit:mkdir /tmp/myrepo1
cd /tmp/myrepo1
git init
Now, you can push your commit to the central repository:touch test
git add test
git commit
Other developers can clone the shared code using the usual command:git push /tmp/myrepo.git master
If you want to be able to track the central repository (i.e. use "git pull" and "git push" directly), you will need your local master branch to track the remote branch.cd /tmp
git clone /tmp/myrepo.git myrepo2
To do this, you can either throw away your local repo and clone again or simply run the following:
That's it. If you want a longer explanation however, have a look at Aaron Toponce's tutorial or see the Debian Alioth instructions.git remote add origin /tmp/myrepo.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master



1 comments:
The initialisation of the bare remote repo is actually slightly easier than you suggest. Instead of doing "git init" to create your local workspace, do "git clone /tmp/myrepo.git". This will complain "warning: You appear to have cloned an empty repository" but your local repo will be set up as a slave (i.e. "git remote -v show" shows /tmp/myrepo.git as origin). This means you can commit to your local master branch, then "git push origin master" and everything will work as expected. Git even sets up the local master branch as a tracker for origin/master. Magic!
Post a Comment