How to Self-Host your own git repository

You can self-host your own git repository, thus avoiding services like github, gitlab, bitbucket. This gives you full control over the repositories. Make as many as you want and make them private or public as you please. Serve it under you own domain. Allow and use whatever licenses you prefer.

Gitea

Gitea, which describes itself as a painless self-hosted Git service, is written in the go language (utilising the hugo generator) and is therefore highly efficient and super fast.

Installation and update instructions

cd into the project folder. If you're updating remove the outdated gitea executable with rm gitea. Look here for the latest version of gitea.

wget -O gitea https://dl.gitea.io/gitea/1.2.0-rc2/gitea-1.2.0-rc2-linux-amd64

chmod +x gitea

Then run ./gitea web, go through the installation process and modify your webserver.

# Apache VHOST
<VirtualHost *:443>
  ServerName git.example.com
  SSLEngine On
  SSLCertificateFile /path/to/cert.crt
  SSLCertificateKeyFile /path/to/cert.key
  ProxyPreserveHost On
  ProxyRequests off
  ProxyPass / http://127.0.0.1:3000/
  ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>

Et voilà.

Run as a service

Check this out and choose your desired service. In the case below systemd is being used.

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target

[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gitea
ExecStart=/home/git/gitea/gitea web
Restart=always
Environment=USER=git HOME=/home/git

[Install]
WantedBy=multi-user.target

When using systemd save and modify this file under /etc/systemd/system and run the following.

systemctl enable gitea
systemctl start gitea