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.
$1.99 domains with SSL purchase!
Pingback: Hosting Git repositories through WebDAV on Snow Leopard Server … Mac Apple
amazing post :)
Tried this but the last step fails. Changes wrt the setup above:
- my client is 10.7.2
- I do’n want usernames and passwords in .netrc because of security
- the realm is digest (this works, as I can mount the WebDAV on the client)
I try it two ways. First way:
- git remote add origin https://repositories.rna.nl:444/ii2.git/
- git push origin master –force -v
And I get:
Pushing to https://repositories.rna.nl:444/ii2.git/
Username:
Password:
error: Cannot access URL https://repositories.rna.nl:444/ii2.git/, return code 22
fatal: git-http-push failed
Second way, using the mounted WebDAV:
- git remote add origin /Volumes/repositories.rna.nl/ii2.git
- git push origin master –force -v
And I get:
Pushing to /Volumes/repositories.rna.nl/ii2.git
fatal: ‘/Volumes/repositories.rna.nl/ii2.git’ does not appear to be a git repository
fatal: The remote end hung up unexpectedly
hermione:ii2.git gerben$ ls -l /Volumes/repositories.rna.nl/ii2.git
ls: objects: No such file or directory
total 19
-rwx—— 1 gerben staff 23 5 Jan 13:11 HEAD
drwx—— 1 gerben staff 2048 5 Jan 13:11 branches
-rwx—— 1 gerben staff 66 5 Jan 13:11 config
-rwx—— 1 gerben staff 73 5 Jan 13:11 description
drwx—— 1 gerben staff 2048 5 Jan 13:12 hooks
drwx—— 1 gerben staff 2048 5 Jan 13:12 info
drwx—— 1 gerben staff 2048 5 Jan 13:11 refs
It seems to be some sort of permission problem. On the server:
bash-3.2# ls -l
total 24
-rw-rw-r– 1 gerben _www 23 5 Jan 13:11 HEAD
drwxrwxr-x 2 gerben _www 68 5 Jan 13:11 branches
-rw-rw-r– 1 gerben _www 66 5 Jan 13:11 config
-rw-rw-r– 1 gerben _www 73 5 Jan 13:11 description
drwxrwxr-x 2 gerben _www 408 5 Jan 13:12 hooks
drwxrwxr-x 2 gerben _www 136 5 Jan 13:12 info
drwxrwxr-x 4 gerben _www 136 5 Jan 13:11 objects
drwxrwxr-x 4 gerben _www 136 5 Jan 13:11 refs
great post … you know a post is great when i take time out to comment..
Just converting all my repos from svn to git ..thanks