4.5 KiB
Create a Git forge with repo2html
This tutorial teaches you how to use repo2html
in a post-receive
hook to
auto-generate HTML representations of bare Git repositories on a remote web
server after you git push
to them.
A Git forge is a website that provides HTML representations of Git repositories, so visitors don't need to clone repositories to view their contents.
Page contents
Requirements
- Chicken Scheme, and eggs:
- Git
- nginx
Prepare your server
This section uses example.com
as a placeholder value. Ensure you replace
example.com
with your own domain when following the procedures below.
This section assumes the following about your server:
- You've generated public and private SSH keys on your local machine.
- You can access your server through SSH and have root access to your server.
- You manage your firewall with
ufw
. - You use
nginx
as your web server. - You use letsencrypt to manage TLS certificates.
- You've added an A record for
git.example.com
.
Set up a git user
Ensure you're in the repo2html git repository, and follow the steps below:
- As root, run
adduser git
. - As root, run
mkdir /var/www/git && chown git:git /var/www/git
. - As root, run
ufw allow 9418
. - Run
su git
. - Run
mkdir ~/.ssh && chmod 700 ~/.ssh
. - Run
touch ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys
. - Add your public ssh key from your local machine to
~/.ssh/authorized_keys
. - Run
mkdir ~/projects
. - Run
git init --bare my-repository
.
After you've set up a git user, follow all procedures that don't require root as the git user.
Set up nginx
-
As root, add the following contents to
/etc/nginx/sites-available/git.example.com
:server { root /var/www/git; index index.html; server_name git.example.com; }
-
As root, run
ln -s /etc/nginx/sites-available/git.example.com /etc/nginx/sites-enabled/
. -
As root, run
nginx -t
to test your nginx configuration. -
As root, run
certbot
, and follow the prompts. -
As root, run
systemctl restart nginx
.
Install repo2html
Ensure you're in the repo2html git repository, and follow the steps below:
- As root, run
make dependencies
. - Run
make
. - As root, run
make install
.
Set up a post-receive hook
- Ensure you're in the
repo2html
Git repository. - Run
mkdir ~/bin
. - Run
echo "PATH="~/bin:$PATH" >> ~/.profile
. - Run
cp assets/post-receive ~/bin
. - Run
chmod u+x ~/bin/post-receive
. - Run
ln -sf ~/bin/post-receive ~/projects/my-repository/hooks/post-receive
. - Run
cp assets/templates/default.html ~/bin
. - In the
assets/post-receive
file, changepath/to/directory/containing/template
to~/bin
Enable cloning over git://
- Ensure you're in the
repo2html
Git repository. - As root, run
cp assets/git-daemon.service /etc/systemd/system
. - As root, run
systemctl enable --now git-daemon.service
.
Test your post-receive hook locally
This section uses example.com
as a placeholder value. Ensure you replace
example.com
with your own domain when following the procedures below.
On your local machine, follow the steps below:
- Run
git init my-repository
. - Run
cd my-repository
. - Run
echo "hello" > my-file.txt
. - Run
git add my-file.txt
. - Run
git commit -m "my first commit"
. - Run
git remote add origin git@example.com:~/projects/my-repository
. - Run
git push
. - Navigate to
https://git.example.com/my-repository
in your browser.