This topic is a compilation from the
gitosis installation
guide on
Ubuntu Server and
Leopard , plus accents from me to some places where problems may arise.
Initially, let's assume that you already know what
git is , and decide why you need to set up a remote repository for this distributed version control system.
Install git.
If you already have git installed, you can skip this part.
To install git you can use the installer or install git from the ports (
MacPorts ). It seems to me more convenient the second way, because the ports in the future can be easily updated to the latest version.
Git using the installer.
We download the
dmg file from the google code , open it, launch the pkg installer file and that's it: git is already in your usus / local /.
')
Git from ports.
I assume that you have already installed the
ports . If not - install, there is nothing complicated, and we will continue.
Run the git installation from source:
sudo port install git-core
If everything went without errors, the newly compiled git is in / opt / local / bin /. I do not accidentally mention the paths, you may need them if something goes wrong.
Install gitosis.
gitosis is a very convenient git server. By and large, this is a set of scripts that are executed when an ssh session is opened. After installation you will get convenient, fast, secure storage for your files. Gitosis, as I wrote above, works in conjunction with ssh. Thus, if you want to set something up for yourself, you have complete freedom of action: look at the current configs, fix something, fix it again, fix, finally, all the mistakes and rather smile.
Download the gitosis source and install it:
mkdir src
git clone git://eagain.net/gitosis.git
cd gitosis
sudo python setup.py install
If the installation process has errors with setuptools try to bypass them:
cd ..
easy_install gitosis
Most likely on this adventure with the installation of gitosis should have ended. Let's try to configure it.
Configure gitosis.
To ensure the proper security level for gitosis, a separate user and a separate group is established.
Create a group and user.
1. Find a free UID and GID for a new user.
sudo dscl . list /Users uid
sudo dscl . list groups gid
(let's say 401 GID and UID are free)
2. Create a git group
sudo dscl . create groups/git
sudo dscl . create groups/git gid 401
3. Create a git user
sudo dscl . create users/git
sudo dscl . create users/git uid 401
sudo dscl . create users/git NFSHomeDirectory /Users/git
sudo dscl . create users/git gid 401
sudo dscl . create users/git UserShell /bin/bash
sudo dscl . create users/git Password '*'
4. Create a home directory (the one indicated in line 3, paragraph earlier)
sudo mkdir /Users/git
sudo chown git /Users/git
sudo chgrp git /Users/git
We initialize gitosis and create a repository with configuration files.
To initialize the configuration files, we need the public part of the rsa user key which will be the first administrator. It will be more clear further. :)
1. If you have not yet created a key for ssh, create it.
ssh-keygen -t rsa
Copy the key to a folder on the server accessible to all users for reading:
scp ~/.ssh/id_rsa.pub your.server.com:/tmp/my_key.pub
or if we are setting up a local server
cp ~/.ssh/id_rsa.pub /tmp/my_key.pub
2. On behalf of our new user, we launch the initialization of gitosis
sudo -H -u git gitosis-init < /tmp/my_key.pub
You will see something like this:
Initialized empty Git repository in ./
Reinitialized existing Git repository in ./
I'd note from myself that I had absolute, not relative, paths.
3. Set up the environment variables for the git user. You can specify your own paths that echo $ PATH displays.
sudo su git (enter your password)
echo "PATH=PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" > ~/.ssh/enviroment
exit
The final touches.
We try to clone the repository with the settings:
git clone git@your.server.com:gitosis-admin.git
and if everything went well, you should see something like
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.
Now you can start working with our remote repository.
Work with gitosis.
First of all, we need to create a new repository and give write access to one or several users. Add the following lines to gitosis.conf:
[group habraTeam]
members = admin ufo
writable = habraProject
Thus, we created the habraTeam group from the admin and ufo users, and allowed them to write to the habraProject repository.
Next, in the keydir folder, we need to put the public part of the rsa keys of our users:
cd gitosis-admin
cp ~/ufo.pub keydir/
Add new files to the commit, create it with a comment and send it to the server:
git add keydir/ufo.pub
git commit -a -m "habraProject . ."
git pull
After executing this code, admin and ufo can write to the habraProject repository, but it does not exist on the server yet.
Create a repository:
mkdir ../habraProject
cd ../habraProject
git init
git remote add origin git@your.server.com:habraProject.git
Now you can add a couple of files to the project, or you can not do this, and immediately upload the skeleton to the server:
git push origin master:refs/heads/master
Epilogue.
I hope this guide helped you, even if you passed it from beginning to end just for fun. I would be happy for amendments, questions, clarifications and additions.
ps For daily work with the repository, I usually use
Gitx - a very handy utility. It still has a few bugs, but it copes well with everyday tasks.