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
- 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.
- 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.
- Open a terminal on the server (or ssh to it) and su git to work as the “git” user.
- Create your repository or repositories (see “Adding repositories” below).
- 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:
- su git
- mkdir .ssh
- chmod 700 .ssh
- Append all of the public keys for your users to the file “.ssh/authorized_keys”, one per line.
Follow these steps for each repository you want to create on the server.
- mkdir projectname.git
- cd projectname.git
- git init –bare
For each repository, add files to the repository by following these steps from the machine on which your files are currently located:
- cd projectname
- git init
- git add *
- git commit -m “Some initial commit text.“
- git remote add origin email@example.com:projectname.git
- 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.
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.