How to setup a server that will automatically receive and save anything you
git push to it.
I wanted to host my git repositories on a private server but didn’t want to
setup something big like Gitlab or Gitorious to do it. I also wanted to be able
git push anything and have the server automatically create a new git
repository and store the data.
I followed the instructions for setting up gitreceive but ran into a small hangup when trying to push a repository:
pre-receive hook declined means that the receiver script that gitreceive installs to
/home/git was crashing. However, the default receiver script does nothing which makes it odd that it would crash. The cause of the problem is that gitreceive is piping the output of
git archive to the receiver script. The receiver script does nothing so exits before
cat cat finish. This causes
cat, then gitreceive to crash with a non-zero exit status causing the
pre-receive hook declined error.
The solution to this is simple. Add the following line to the receiver script:
This will wait for gitreceive to finish piping the archived repository before exiting. Now you can push a new repository and gitreceive will automatically create and receive it.
Note: you do not need to save a copy of the archive that gitreceive is piping into the receiver script. The repository’s data is still being saved in
/home/git/<reponame>. You can verify this by running