MacOS – Setting up a git (ssh) server using OS X Server

gitmacosserver.appssh

I would like to use OS X Server to set up a git server that I can ssh into from other machines on my network.

I realize that Xcode Service has repository functionality built in, but I am looking for a more universally accessible system (from Windows or other machine without Xcode), and my Xcode Service setup broke with Yosemite anyway. I also realize that git is already installed on my machine and that I can set up an ssh server by a method like this or this, but I don't want to make a new user or deal with things on the local machine level like the first post says (I have a full server already and I want to use its resources), and I don't want to install gitolite/gitlab/etc.

To sum up, I am looking for a way to host ssh-accessible git repositories on my machine using only git and OS X Server. Thank you for your time.

Best Answer

You need to create a "bare" git repo: a repository that can never have files checked out. Everyone pulls and pushes from the server like normal, but nobody can actually work on the server (unless they make a non-bare clone).

If you are creating a new repository called "my_bare_repo.git", you can make it bare like so:

cd /Users/git (or whatever)
git init --bare my_bare_repo.git

Using your git server

On the client machine, you would clone the repo like so:

git clone ssh://user@yourmachine.domain.com/Users/git/my_bare_repo.git

If you have an existing local repo, you can add a remote origin like so:

git remote add origin ssh://user@yourmachine.domain.com/Users/git/my_bare_repo.git

Then use the server app to set up "sharing only" users that can use ssh services. You can manage the users and profiles locally or remotely through web and/or server app. The ssh access is controlled in the Server entry in the top left - then click on Settings on the right and select SSH.