How to set up a public Git repository in Unix

gitrepositoryunix

I've set up a number of private repos where I commit via SSH but I'm having problems setting up a public one. Here's what I've done so far:

Log into my server via ssh

$ cd public_html/repos/
$ mkdir test
$ cd test 
$ git --bare init
$ touch git-daemon-export-ok # tell GIT it's ok to export this project
$ chmod 777 -R ../test #making sure the directory had full read write execute permissions
$ exit # exit out of ssh

$ mkdir test_porject
$ cd test_project
$ touch README.txt
$ git init #Initialized empty Git repository in ~/test_porject
$ git add .
$ git commit -m "initial commit"
$ git remote add origin http://repos.mydomain.com/test
$ git push origin master

this is the error I get:
error: The requested URL returned error: 500 while accessing http://repos.mydomain.com/test/info/refs
fatal: HTTP request failed

Huh???? Not sure why this isn't working. If you go to http://repos.mydomain.com/ I don't get any errors. Any help would be much appreciated.

Best Answer

I am suspicious that your transcript above does not in fact represent the actual commands that you typed. Here's how you can set up an http-accessible repository, and the commands (and output) here are exactly what I have typed in:

Creating the repository:

$ mkdir -p public_html/git
$ cd public_html/git
$ git init --bare testrepo.git
Initialized empty Git repository in /home/lars/public_html/git/testrepo.git/
$ cd testrepo.git
$ mv hooks/post-update.sample hooks/post-update
$ chmod 755 hooks/post-update

Populating it with some commits:

$ cd ~/tmp/
$ mkdir testrepo
$ cd testrepo
$ git init
Initialized empty Git repository in /home/lars/tmp/testrepo/.git/
$ echo this is a test > myfile
$ git add myfile
$ git ci -m 'added myfile'
[master (root-commit) eea6564] added myfile
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 myfile
$ git remote add origin ~/public_html/git/testrepo.git
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 233 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/lars/public_html/git/testrepo.git/
 * [new branch]      master -> master

Cloning it via http:

$ cd ~/tmp
$ git clone http://localhost/~lars/git/testrepo.git testrepo-cloned
Cloning into testrepo...
$ ls -A testrepo-cloned/
.git  myfile

If you run through this and it doesn't work, I strongly suspect an issue with your webserver configuration.