1<- Back	/	codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i# Setup your own git hosting service		codemadness.org	70
i		codemadness.org	70
iLast modification on 2022-08-07		codemadness.org	70
i		codemadness.org	70
i**This article assumes you use OpenBSD for the service files and OS-specific		codemadness.org	70
iexamples.**		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Why		codemadness.org	70
i		codemadness.org	70
iA good reason to host your own git repositories is because of having and		codemadness.org	70
ikeeping control over your own computing infrastructure.		codemadness.org	70
i		codemadness.org	70
iSome bad examples:		codemadness.org	70
i		codemadness.org	70
h* The SourceForge ads/malware/hijack controversies. Injecting malware into projects.	URL:https://en.wikipedia.org/wiki/SourceForge#Controversies	codemadness.org	70
h* As of 2019-10-23 Gitlab added telemetry to their software.	URL:https://gitlab.com/gitlab-org/gitaly/issues/2113	codemadness.org	70
h* On 2019-10-24 Gitlab reverted it again because many people complained.	URL:https://about.gitlab.com/blog/2019/10/10/update-free-software-and-telemetry/	codemadness.org	70
h* On 2020-11-16 Github reinstated youtube-dl, to reverse a Digital Millennium Copyright Act (DMCA) takedown.	URL:https://github.blog/2020-11-16-standing-up-for-developers-youtube-dl-is-back/	codemadness.org	70
h* On 2021-03-11 Github (owned by Microsoft) removes exploit code for Microsoft Exchange vulnerabilities.	URL:https://arstechnica.com/gadgets/2021/03/critics-fume-after-github-removes-exploit-code-for-exchange-vulnerabilities/	codemadness.org	70
h* On 2022-04-16 Russian software developers are reporting that their GitHub accounts are being suspended without warning if they work for or previously worked for companies under US sanctions.	URL:https://www.bleepingcomputer.com/news/security/github-suspends-accounts-of-russian-devs-at-sanctioned-companies/	codemadness.org	70
h* On 2022-08-04 GitLab plans to delete dormant projects in free accounts.	URL:https://www.theregister.com/2022/08/04/gitlab_data_retention_policy/	codemadness.org	70
h* On 2022-08-05 GitLab U-turns on deleting dormant projects after backlash.	URL:https://www.theregister.com/2022/08/05/gitlab_reverses_deletion_policy/	codemadness.org	70
i		codemadness.org	70
iThe same thing can happen with Github, Atlassian Bitbucket or other similar		codemadness.org	70
iservices.  After all: they are just a company with commercial interests.  These		codemadness.org	70
ionline services also have different pricing plans and various (arbitrary)		codemadness.org	70
irestrictions.  When you host it yourself the restrictions are the resource		codemadness.org	70
ilimits of the system and your connection, therefore it is a much more flexible		codemadness.org	70
isolution.		codemadness.org	70
i		codemadness.org	70
hAlways make sure you own the software (which is »Free« or open-source) and you	URL:https://www.gnu.org/philosophy/free-sw.html	codemadness.org	70
ican host it yourself, so you will be in control of it.		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Creating repositories		codemadness.org	70
i		codemadness.org	70
iFor the hosting it is recommended to use a so-called "bare" repository.  A bare		codemadness.org	70
irepository means no files are checked out in the folder itself.  To create a		codemadness.org	70
ibare repository use git init with the --bare argument:		codemadness.org	70
i		codemadness.org	70
i        $ git init --bare		codemadness.org	70
i		codemadness.org	70
iI recommend to create a separate user and group for the source-code		codemadness.org	70
irepositories.  In the examples we will assume the user is called "src".		codemadness.org	70
i		codemadness.org	70
iLogin as the src user and create the files. To create a directory for the		codemadness.org	70
irepos, in this example /home/src/src:		codemadness.org	70
i		codemadness.org	70
i        $ mkdir -p /home/src/src		codemadness.org	70
i        $ cd /home/src/src		codemadness.org	70
i        $ git init --bare someproject		codemadness.org	70
i        $ $EDITOR someproject/description		codemadness.org	70
i		codemadness.org	70
iMake sure the git-daemon process has access permissions to these repositories.		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Install git-daemon (optional)		codemadness.org	70
i		codemadness.org	70
iUsing git-daemon you can clone the repositories publicly using the efficient		codemadness.org	70
igit:// protocol. An alternative without having to use git-daemon is by using		codemadness.org	70
i(anonymous) SSH, HTTPS or any public shared filesystem.		codemadness.org	70
i		codemadness.org	70
iWhen you use a private-only repository I recommend to just use SSH without		codemadness.org	70
igit-daemon because it is secure.		codemadness.org	70
i		codemadness.org	70
iInstall the git package. The package should contain "git daemon":		codemadness.org	70
i		codemadness.org	70
i        # pkg_add git		codemadness.org	70
i		codemadness.org	70
iEnable the daemon:		codemadness.org	70
i		codemadness.org	70
i        # rcctl enable gitdaemon		codemadness.org	70
i		codemadness.org	70
iSet the gitdaemon service flags to use the src directory and use all the		codemadness.org	70
iavailable repositories in this directory. The command-line flags "--export-all"		codemadness.org	70
iexports all repositories in the base path. Alternatively you can use the		codemadness.org	70
i"git-daemon-export-ok" file (see the git-daemon man page).		codemadness.org	70
i		codemadness.org	70
i        # rcctl set gitdaemon flags --export-all --base-path="/home/src/src"		codemadness.org	70
i		codemadness.org	70
iTo configure the service to run as the user _gitdaemon:		codemadness.org	70
i		codemadness.org	70
i        # rcctl set gitdaemon user _gitdaemon		codemadness.org	70
i		codemadness.org	70
iTo run the daemon directly as the user _gitdaemon (without dropping privileges		codemadness.org	70
ifrom root to the user) set the following flags in /etc/rc.d/gitdaemon:		codemadness.org	70
i		codemadness.org	70
i        daemon_flags="--user=_gitdaemon"		codemadness.org	70
i		codemadness.org	70
iWhich will also avoid this warning while cloning:		codemadness.org	70
i		codemadness.org	70
i        "can't access /root/.git/config"		codemadness.org	70
i		codemadness.org	70
iNow start the daemon:		codemadness.org	70
i		codemadness.org	70
i        # rcctl start gitdaemon		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Cloning and fetching changes		codemadness.org	70
i		codemadness.org	70
iTo test and clone the repository do:		codemadness.org	70
i		codemadness.org	70
i        $ git clone git://yourdomain/someproject		codemadness.org	70
i		codemadness.org	70
iif you skipped the optional git-daemon installation then just clone via SSH:		codemadness.org	70
i		codemadness.org	70
i        $ git clone ssh://youraccount@yourdomain:/home/src/src/someproject		codemadness.org	70
i		codemadness.org	70
iWhen cloning via SSH make sure to setup private/public key authentication for		codemadness.org	70
isecurity and convenience.		codemadness.org	70
i		codemadness.org	70
iYou should also make sure the firewall allows connections to the services like		codemadness.org	70
ithe git daemon, HTTPd or SSH, for example using OpenBSD pf something like this		codemadness.org	70
hcan be set in »/etc/pf.conf«:	URL:https://man.openbsd.org/pf.conf	codemadness.org	70
i		codemadness.org	70
i        tcp_services="{ ssh, gopher, http, https, git }"		codemadness.org	70
i        pass in on egress proto tcp from any to (egress) port $tcp_services		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Pushing changes		codemadness.org	70
i		codemadness.org	70
iAdd the repository as a remote:		codemadness.org	70
i		codemadness.org	70
i        $ git remote add myremote ssh://youraccount@yourdomain:/home/src/src/someproject		codemadness.org	70
i		codemadness.org	70
iThen push the changes:		codemadness.org	70
i		codemadness.org	70
i        $ git push myremote master:master		codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Git history web browsing (optional)		codemadness.org	70
i		codemadness.org	70
iSometimes it's nice to browse the git history log of the repository in a web		codemadness.org	70
ibrowser or some other program without having to look at the local repository.		codemadness.org	70
i		codemadness.org	70
1* »Stagit« is a static HTML page generator for git.	/phlog/stagit	codemadness.org	70
1* »Stagit-gopher« is a static page generator for	/phlog/stagit-gopher	codemadness.org	70
h  »gopher« and	URL:http://gopherproject.org/	codemadness.org	70
1  geomyidae.	/scm/geomyidae	bitreich.org	70
i* cgit is a CGI-based program which shows HTML views of your repository, see		codemadness.org	70
1  also the page: »OpenBSD httpd, slowcgi and cgit«.	/phlog/openbsd-httpd-and-cgit	codemadness.org	70
i		codemadness.org	70
iIt's also possible with these tools to generate an Atom feed and then use a		codemadness.org	70
iRSS/Atom reader to track the git history:		codemadness.org	70
i		codemadness.org	70
h* An example url from cgit: »Linux kernel tree«.	URL:https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/atom/?h=master	codemadness.org	70
0* An example url from stagit for the »commit log«.	/git/stagit/atom.xml	codemadness.org	70
0* An example url from stagit for the »releases«.	/git/stagit/tags.xml	codemadness.org	70
i		codemadness.org	70
1My »sfeed« program can be used as a RSS/Atom reader.	/phlog/sfeed	codemadness.org	70
i		codemadness.org	70
i		codemadness.org	70
i## Setting up git hooks (optional)		codemadness.org	70
i		codemadness.org	70
iUsing git hooks you can setup automated triggers, for example when pushing to a		codemadness.org	70
irepository.  Some useful examples can be:		codemadness.org	70
i		codemadness.org	70
1* For stagit: update the repo files (example post-receive hook).	/git/stagit/file/example_post-receive.sh.gph	codemadness.org	70
i* Send an e-mail with the commit subject and message.		codemadness.org	70
h* Log/notify commits and changes to an IRC channel using a fifo: »ii«.	URL:https://tools.suckless.org/ii/	codemadness.org	70
i* Create a release tarball and checksum file on a tag push/change.		codemadness.org	70
i* Checkout files for website content.		codemadness.org	70
.
