1 # Scripts for self-hosted git admin
3 Recently I've been using my own git server [1,2] to host my repositories, and for simplicity I decided to go with GitWeb [3]. This also means that I don't get a web management UI, which turns out is a great thing with a few helper scripts.
5 => https://git.unlimited.pizza [1] git @ unlimited.pizza (https)
6 => gemini://gemini.unlimited.pizza/git [2] git @ unlimited.pizza (gemini)
7 => https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb [3] GitWeb
9 ## repo_name to fetch repository name
11 I want to use the same <username>/<repo> structure across services, and this utility helps me extract it. It fetches the push origin remote, grabs the last two fragments of the URL and then removes any leading tilde (for compatibility with sourcehut). I don't really use this one directly, but all other scripts depend on it.
15 git remote -v | grep origin | grep push | grep -o '[^:/]\+\/[^/]\+\s\+' | grep -o '[^~:]\+\/[^ ]\+'
19 ## sync_to_conchos creates the repository
21 My upstream is called conchos [4], and this function checks if the origin exists and then pushes everything. The server is setup to create a private repository if it's not found.
24 function sync_to_conchos {
25 if git config remote.conchos.url > /dev/null; then; else
26 git remote add conchos "git@git.unlimited.pizza:$(repo_name)"
28 git push conchos --all
29 git push conchos --tags
33 % cd ~/projects/web/blog && sync_to_conchos
36 => https://en.wikipedia.org/wiki/Rio_Conchos [4] Rio Conchos
38 ## make_public /make_private control a repo's visibility
40 The git daemon controls public access with a file called `git-daemon-export-ok`, so controlling visibilitiy is as easy as touching or removing a file. If I run these from the root of the project, it controls its visibility.
43 function make_public {
44 ssh git@git.unlimited.pizza -T "touch /srv/git/$(repo_name)/git-daemon-export-ok"
47 function make_private {
48 ssh git@git.unlimited.pizza -T "rm /srv/git/$(repo_name)/git-daemon-export-ok"
52 % cd ~/projects/web/blog && make_public
55 ## describe adds a description for the repo
57 The git daemon uses a file called `description` to show a description on the web.
61 ssh git@git.unlimited.pizza -T "echo '$1' > /srv/git/$(repo_name)/description"
65 % cd ~/projects/web/blog && describe 'An (almost) ephemeral blog #cli'
70 This has made managing my repositories a lot easier as I don't have to fiddle with a web UI at all. If you're also self-hosting git, maybe you'll also find them helpful!