Hosting Git repositories through WebDAV on Snow Leopard Server
This will be quick and dirty; the necessity comes from a particular source code that I can't trust to host online to a third party vendor/provider.
I have a Snow Leopard Server, so I will make use of the tools provided, there's little information about the subject, so here it is.
Also I choose WebDAV since my SSH is blinded to the outside world, in order to access it I require a VPN connection, but since I want to share some repo to the outside world, WebDAV comes handy.
I host my repositories in a subdomain, so before anything, open up your DNS Server Admin section and start editing by adding your new shiny hostname as you please by adding a new record there.
I assume you are using a subdomain along the lines of repositories.yourdomain.com; you don't have to do this step if using an ip address, this is up to you.
Login into your server through ssh or the way you like and create a repositories index directory somewhere.
In my particular setup I have this structure for my websites:
/Sites/kain/mydomain.com/[www, macruby, etc]
So go where you like and create a directory, I'll use repositories
mkdir /Sites/kain/mydomain.com/repositories
Assign this directory to the _www user
chown -R _www:_www /Sites/kain/mydomain.com/repositories cd /Sites/kain/mydomain.com/repositories
Start creating a new directory that will host the git repository:
mkdir myproject.gitAfter that go in the Web section, and create (or copy) a new website.
Relevant General setup:
Host name: repositories.yourdomain.com
Web folder: /Sites/kain/mydomain.com/repositories
Relevant Options setup:
Folder listing: enabled (not really necessary but useful for testing what you see in index later)
WebDAV: enabled
Rest disabled
Relevant Realm setup:
create a new realm by clicking the plus sign
Realm name: myproject
Authentication: Basic (will try Digest/Kerberos in future)
Select Location for the select widget instead of Folder and write
/myproject.gitIn the right section now add your users that will have access, after that change their permissions.
Since my repos are private I only keep the users that have write access there by setting their permissions to Browse and Read/Write WebDAV, None for Everyone.
Relevant Logging setup:
enable logging as you please
Relevant Security setup:
I choose to use SSL for this tutorial, so you are going to use a certificate and port 443.
Save and close Server Admin.
Let's go back to our SSH server session.
Enter your project directory and exec those commands:
cd /Sites/kain/mydomain.com/repositories/myproject.git sudo git init --bare sudo chown -R _www:_www . sudo mv hooks/post-update.sample hooks/post-update sudo git update-server-info
Now switch to your client.
Edit your ~/.netrc file with those informations:
machine repositories.mydomain.com
login myusername
password mypasswordEnter your project dir and exec those commands:
cd myproject git config --global http.sslVerify false # If you don't own a valid SSL certificate on your server, skip --global to enable this option only for this project git init # gitify the directory git add . # add files to git repo git commit -m "hi" # first commit git remote add origin https://repositories.mydomain.com/myproject.git/ # end slash is important git push origin master --force -v
Now edit this file, always in your project root dir:
mate .git/configAnd add
[branch "master"] remote = origin merge = refs/heads/master
This way you can do git push and git pull normally.
Done.
Related posts:
Enjoy this article?
Additional comments powered by BackType