Monday, February 04, 2008

Git-ty up (Part 2)

Setting up your own Git server. I learned how to setup using this guide. I am duplicating the guide here for a quick reference.
  1. Installing GIT
    • If it doesn't exist on ubuntu. For some reason, GIT needs it.
      • touch /etc/inittab
    • sudo apt-get install git-arch git-cvs git-svn git-email git-daemon-run git-core curl python-setuptools
    • sudo adduser --system --shell /bin/sh --gecos 'GIT Version Control' --group --disabled-password --home /path/to/git_home_directory git_user_name (set up a user to handle all Git request)
  2. Installing gitosis-admin (for user management)
    • In any directory
      • git clone git://eagain.net/gitosis.git
    • cd gitosis
    • sudo python setup.py install
  3. Setting up initial user
    • On local machine generate a public/private ssh key it it doesn't already exist
      • ssh-keygen -t rsa
    • Copy the public key to the Git server and put it in a publicly readable folder
      • scp ~/.ssh/id_rsa.pub user@git_server:/tmp/id_rsa.pub
    • Back on Git server (as a user with sudo privileges)
      • sudo -H -u git gitosis-init < /tmp/id_rsa.pub
    • Git uses SSH as the default transport to communicate with the server, so make sure user_git is allowed in the sshd AllowUsers directive.
  4. Adding users
    • On local machine with the private key
    • Some of us will run SSH on a non standard port so it may be wise to create a .ssh/config file and add a directive to establish connection to the Git server.
      • vi ~/.ssh/config
      • Host git_server
        User git
        Hostname <ip of git server>
        Port <port ssh is listening on>
      • Quit and save.
    • Clone the gitosis-admin file for user management.
      • gitosis-clone git_server:gitosis-admin.git
      • cd gitosis-admin
      • Copy the new users SSH public keyfile to the keydir folder with the format user@server.pub. The .pub is absolutely necessary otherwise the user will not be added. The user@server is the name which appears after the == IN the public keyfile.
      • vi gitosis.conf
      • Add new users you would like to administer gitosis or keep them for other repositories.
      • Quit and save.
      • git commit -a -m "Whatever commit message you like to add"
      • git push origin master:refs/heads/master

  5. Adding repositories
    • Go back to the gitosis-admin folder on your local machine.
    • vi gitosis.conf
    • On a new line, add
      • [group repo_name]
        writable = repo_name
        members = user1@server user2@server

    • Quit and save.
    • git commit -a -m "Whatever commit message you like to add"
    • git push origin master:refs/heads/master

In the final part, I'll list a few basic commands to get started.

No comments: