May 142012

I have a side project I’m working on in collaboration with a friend, for which we needed version control. So I set out this weekend to set up a git server on my personal server, which runs Mac OS X 10.6.8. Fortunately, git is already there, courtesy of the standard Apple developer tools, so that part was already in place.

After spending some time reading through Pro Git on the Safari bookstore, as well as surfing the web, I figured out how to do it and got it all set up and working. I figured that, having done so, I should share what I did. So here we go!

Creating the server

  1. Start up Workgroup Manager and create a new “git” user. Set the startup shell for this user to a custom shell and enter “/usr/bin/git-shell”. This will prevent the “git” user from logging into a bash shell.
  2. In the Server Admin utility, add the “git” user to the list of users that have SSH access to the server; this is done in the “Access” panel.
  3. Open a terminal on the server (or ssh to it) and su git to work as the “git” user.
  4. Create your repository or repositories (see “Adding repositories” below).
  5. Add files to the repository; see “Adding files” below.

Giving access to users

In order to let contributors access the server, we’ll use SSH keys. Gather SSH public keys from everyone that will be contributing to the project. Then follow these steps:

  1. su git
  2. cd
  3. mkdir .ssh
  4. chmod 700 .ssh
  5. Append all of the public keys for your users to the file “.ssh/authorized_keys”, one per line.

Adding repositories

Follow these steps for each repository you want to create on the server.

  1. mkdir projectname.git
  2. cd projectname.git
  3. git init –bare

Adding files

For each repository, add files to the repository by following these steps from the machine on which your files are currently located:

  1. cd projectname
  2. git init
  3. git add *
  4. git commit -m “Some initial commit text.
  5. git remote add origin
  6. git push -u origin master

At this point, any of your users whose keys you’ve authorized can access your git server and can both push and fetch files from it.

Wrapping up

I wrote this little guide up from jotted-down notes and memory, so if I’ve made any mistakes, be sure to let me know so I can fix it. I fully expect I will refer back to this in the future (which is part of why I wrote it all down here)! I hope this helps you out too.

 Posted by at 4:20 PM

  3 Responses to “Setting up a small team git server on OS X”

  1. You failed to mention that under normal circumstances,
    mkdir .ssh
    should be followed by
    chmod 700 .ssh

  2. Thanks, Jerry. I’ve updated the post accordingly.

  3. Thank you. The original post was very helpful.

This site uses Akismet to reduce spam. Learn how your comment data is processed.