Deploying git server on Mac OS X Leopard

    This topic is some compilation from the installation guide for gitosis on Ubuntu Server and Leopard , plus accents from me to some places where problems may arise.

    Initially, suppose you already know what git is , and decide why you need to configure a remote repository for this distributed version control system.

    Git installation.

    If git is already 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 ports in the future can be easily updated to the latest version.

    Git using the installer.

    Download the dmg file with google code , open, run the pkg installer file and that’s it: git is already in your / usr / local /.

    Git from ports.

    I will assume that you have already installed the ports . If not, install, there is nothing complicated, and continue.
    We start the installation of git from the sources:
    sudo port install git-core
    If everything went smoothly, the just compiled git is in your / 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 receive convenient, fast, secure storage for your files. Gitosis, as I wrote above, works in conjunction with ssh. Thus, if you want to configure something “for yourself”, you have complete freedom of action: look at the current configs, fix something, fix it again, fix, finally, all the errors and smile pretty.
    Download the gitosis sources and install it: If there are errors during the installation process with setuptools, we try to work around them: Most likely, the adventures with installing gitosis should have ended. Let's try to configure it.
    mkdir src
    git clone git://
    cd gitosis
    sudo python install

    cd ..
    easy_install gitosis

    Configure gitosis.

    To ensure the proper level of security for gitosis, a separate user and a separate group are set up.

    Create a group and user.

    1. Find the free UID and GID for the new user (let's say 401 GID and UID are free) 2. Create a git group 3. Create a git user 4. Create a home directory (the one indicated in line 3, the item earlier)
    sudo dscl . list /Users uid
    sudo dscl . list groups gid

    sudo dscl . create groups/git
    sudo dscl . create groups/git gid 401

    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 '*'

    sudo mkdir /Users/git
    sudo chown git /Users/git
    sudo chgrp git /Users/git

    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 clearer further. :)
    1. if you have not created a key for ssh yet - we create it.
    ssh-keygen -t rsa
    copy the key to the folder on the server that is readable by all users:
    scp ~/.ssh/
    or, if we are setting up a local server
    cp ~/.ssh/ /tmp/
    2. On behalf of our new user, we start the gitosis initialization.
    sudo -H -u git gitosis-init < /tmp/
    You will see something like this: I’ll notice on my own that the paths were absolute, not relative . 3. Set up environment variables for the git user. You can specify your paths that echo $ PATH prints to you.
    Initialized empty Git repository in ./
    Reinitialized existing Git repository in ./

    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

    The final touches.

    We are trying to clone the repository with the settings:
    git clone
    and if everything went well, you should see something like. Now you can start working with our remote repository.
    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.

    Work with gitosis.

    First of all, we need to create a new repository and give write rights to one or more users. Add the following lines to gitosis.conf: Thus, we created the habraTeam group from the users admin and ufo, 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: Add new files to the commit, create it with a comment and send it to the server: After executing this code, admin and ufo can write to the habraProject repository, but it does not yet exist on the server. Create a repository: 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:
    [group habraTeam]
    members = admin ufo
    writable = habraProject

    cd gitosis-admin
    cp ~/ keydir/

    git add keydir/
    git commit -a -m "habraProject настроен. Можно взлетать."
    git pull

    mkdir ../habraProject
    cd ../habraProject
    git init
    git remote add origin

    git push origin master:refs/heads/master


    I hope this guide has helped you, even if you went through it from start to finish just for fun. I will be glad to amendments, questions, clarifications and additions.
    ps For everyday work with the repository, I usually use Gitx - a very convenient utility. There are still a few bugs in it, but it copes well with everyday tasks.

    Also popular now: