Wednesday, January 27, 2010

2 Minute Guide to Remote Git Repository Creation

This is basically the same as the 37signals Git Resources Creating a remote repository section, with some minor modifications and clarifications. Both are geared toward someone who wants to create a repository accessible to only people in certain group.

First off, login to the remote server:
ssh userid@yourremoteserver
Let's assume that you already setup a user "otheruserid" (maybe you created a "git" user) that is in the same group as the developers that need access to the repository. We'll assume that "userid" is a member of that same group. It is a better idea to create this as a more generic user that won't be removed later, so that the group membership can be dynamic (as people come and go). Note that the .git at the end of the path is optional.
sudo su - otheruserid
mkdir -p /some/path/nameofmyproject.git
chmod 775 /some/path/nameofmyproject.git
cd /some/path/nameofmyproject.git
For this next part, don't change group to the group name. It is literally supposed to be this exact line if you want to share with the group. If you want it to be open to the public, you'd specify "all" instead of "group".
git --bare init --shared=group
(Ctrl-D twice to get back to your local environment)
Richard mentioned that if you want to create a private group repository and manage permissions across everything a little better you could use getacl/setacl (even though you should still use --shared=group, just in case). You can probably find more on permissions via a search, but berliOS has a GIT HowTo with a section on How to control access to your GIT Repository just as one example of fine-grained permissions.

Back on your computer, or wherever you want to develop, do the following:

mkdir -p /path/to/my/projects/dir
cd /path/to/my/projects/dir
mkdir nameofmyproject
Be careful that you change directory into your new nameofmyproject directory, otherwise you could end up adding everything that is not nailed down (via git) into your new repository!
cd nameofmyproject
git init
git remote add origin userid@yourremoteserver:/some/path/nameofmyproject.git
touch .gitignore
git add .
git commit -m "Initial commit"
git push --all
Ok, now you have the local copy, but if you try to do "git pull" it won't work because the following isn't defined in .git/config:
[branch "master"]
 remote = origin
 merge = refs/heads/master

You could edit .git/config to add that to the bottom, or better yet- blow away the local project directory you just created (please back it up first if it is important!) and clone from the remote repo:

cd ..
rm -rf nameofproject (warning: back it up first, if you are unsure about removing it)
git clone ssh://userid@yourremoteserver/some/path/nameofmyproject.git

If someone else wants to clone the repository to work with it locally, they do this:

git clone ssh://userid@yourremoteserver/some/path/nameofmyproject.git

No comments: