Setting up git

Git is yet another open source version control, and seems to be the tool of choice for contemporary coding mavericks. I still prefer svn and cvs, for centralised version control, but can appreciate why some projects may require distributed repositories as afforded by git.

Setting up a central git repository on a server is easy. You basically setup a user, whose home directory is used to store the repositories, and allow access to people using keys, where the user retain their private key and their public key is saved as an authorised key for the git user account.

Note: I've documented the steps I used below for my benefit. The name of the server has been replace with <SERVER>, and the source code repository example is project.git


  1. groupadd git
  2. useradd -g git -d /home/git -m git
  3. su - git
  4. mkdir -p /home/git/.ssh
  5. cat id_rsa.pub > /home/git/.ssh/authorized_keys
  6. chmod 600 /home/git/.ssh/authorized_keys
  7. chmod 700 /home/git/.ssh
  8. exit
  9. vi /etc/passwd     # change the shell for user git from /bin/bash to /usr/bin/git-shell
    1. /usr/bin/git-shell
  10. vi /etc/ssh/sshd_config     # ensure that the following are uncommented
    1. RSAAuthentication yes
    2. PubkeyAuthentication yes
    3. AuthorizedKeysFile      .ssh/authorized_keys
  11. service sshd restart
Git Notes
  • Create repositories
  1. cd /home/git
  2. mkdir project.git
  3. cd project.git
  4. git --bare init
  • Initially adding to the repository
  1. git init
  2. git add .
  3. git commit -m 'initial commit'
  4. git remote add origin git@<SERVER>:/home/git/project.git
  5. git push origin master
  • Other users cloning the repository
  1. git clone git@<SERVER>:/home/git/project.git
  1. http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server

No comments:

Post a Comment