~/Blog

Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Mirror Public Repositories

Published on

Updated on

2 minute reading time

Git is designed to be decentralized. However, many people treat it as a centralized solution by depending on services such as GitHub. What we’ve seen through the youtube-dl debacle is that repositories that we depend on can be taken down.

This isn’t to say that GitHub is evil and that we should move to Bitbucket, Gitlab, Source Hut, etc. But this is more of a commentary on what happens when we depend on one service to host our code. Git is designed to be decentralized, we should make use of that fact!

Also, alleged illegal activity is not the only reason repositories are taken down from the Internet. Sometimes, the developer themselves decide to take it down.

As individuals, we can maintain mirrors of repositories we care about. That way if it ever gets removed from a particular service, we’re not out of luck.

The simplest way to go about this is to git clone the repositories you care about, and regularly pull through a cron job or systemd timer. Through systemd maybe it’ll look like this:

/etc/systemd/system/refresh-hugo.service

[Unit]
Description=Pull latest changes from Hugo

[Service]
Type=oneshot
WorkingDirectory=/home/brandonrozek/repo/hugo
ExecStart=/usr/bin/git pull

[Install]
WantedBy=multi-user.target

/etc/systemd/system/refresh-hugo.timer

[Unit]
Description=Pull latest changes from Hugo every week
Requires=refresh-hugo.service

[Timer]
Unit=refresh-hugo.service
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target

Alternatively, you can use a self-hosted git server instance such as Forgejo to set up pull mirrors through the migration tool. As of the time of writing, this is what I currently do with repositories at https://git.brandonrozek.com/github

I do recommend only mirroring/pulling infrequently such as weekly. We don’t want to induce unnecessary load on these centralized services.

Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter