Kamal Nasser

Mirroring Private Git Repositories Locally: The Easy Way

July 07 2013 post

Some of Capisso's projects depend on various private Cartalyst repositories. Since our code is open-source, we needed to allow everyone to access Cartalyst's repositories (Cartalyst's code is licensed under the OSI BSD 3 license which permits distributing code).

The easiest way of mirroring a private git repo is as follows:

For the sake of this post, the private repo will be [email protected]:example/repo.git.

Start off by setting up a webserver. DigitalOcean has some nice articles on doing that:

You can skip the PHP/MySQL bit of the articles.

Let's assume our document root is /srv/www/git.domain.com/public_html.

SSH into your server.

ssh user@IP

Make sure Git is installed:

# Ubuntu/Debian:
apt-get install git-core
# CentOS/Fedora:
yum install git

cd into your document root:

cd /srv/www/git.domain.com/public_html

Clone the private repo as a bare repository:

git clone --bare [email protected]:example/repo.git

cd into the bare repository and run git update-server-info:

cd repo.git
git update-server-info

Enable the default post-update hook that runs git update-server-info automatically when you pull:

mv hooks/post-update{.sample,}

That's it. Your "private" repo is now ready for everyone to use. Make sure it works by trying to clone it locally and seeing if it works:

git clone http://git.domain.com/repo.git