Marcel Kapfer

„Mirroring“ my open-source Git repos to my Gitea instance

2020-08-30

535 words, ~ 3 min reading time

code git

tl;dr: GitLab will still be my primary Git platform for my public projects/repositories, but these repositories can now also viewed at my Gitea instance at git.mmk2410.org.

You may have noticed that I added a link to a Gitea instance on some places next to a link to my GitLab account. The reason behind this is the following.

For years I always had a Git “server” running on my virtual private server (VPS) for private purposes. There was also a time where I had all repositories hosted exclusively on a private Phabricator instance and the only way to interact with them was through it. After that I moved all my public repositories to GitLab and mirror them to my GitHub account. I further used the Phabricanntor instance for private purposes, later switched to a cgit with gitolite installation and a few months ago I set up a Gitea instance because I needed something with Git LFS support and Gitea provides that.

Since I like Gitea quite a bit I started moving some (and as of now any) public repositories to my Gitea instance and mirroring them Gitlab. I have not made this change public since actually nothing changes in practice: I still accept issues and merge requests on GitLab and will keep doing so. In case I myself create issues on my public repositories I will do it also on GitLab. Actually creating a account and interacting with my Gitea instance is currently not possible

So GitLab will still be my primary code hosting platform for public projects/repositories. At least for now and if this changes I will inform you in advance.

Since I do not know where this leads in the future, I start linking to my own Gitea instance.

Mirroring a repository from Gitea to Gitlab

While the main reason for this post was to inform you about the reason for the new links to my Gitea instance you may be also interested in how achieve the mirroring from Gitea to Gitlab.

I setup the sync a few months ago by following a blog post I found. I did not write down the URL of that post so I searched right now for the post. I am not entirely sure but I think it was a German post on Gurkengewuerz called Gitea zu Github mirror.

The idea is quite simple:

  1. Create a SSH key e.g. with ssh-keygen -t ed_25519 -b 4096 -f gitea
  2. Add the public key to the Gitlab repository
  3. Create a post-receive Git hook in the Gitea repository with the following content.
#!/usr/bin/env bash

downstream_repo="Remote SSH URL"
# if tmp worries you, put it somewhere else!
pkfile="/tmp/gitlab-mirror-ed25519"

if [ ! -e "$pkfile" ]; then # unindented block for heredoc's sake
cat > "$pkfile" << PRIVATEKEY
### ENTER YOUR PRIVATE KEY HERE ###
fi

chmod 400 "$pkfile"
export GIT_SSH_COMMAND="ssh -oStrictHostKeyChecking=no -i \"$pkfile\""
# if you want strict host key checking, just add the host to the known_hosts for
# your Gitea server/user beforehand
git push --mirror "$downstream_repo"

(Hmm. Since there are comments in English maybe I found another block back then which uses the same idea. If I find it again I will link it here.)

If you would like to comment on this post, feel free to write me a mail at comment(at)mmk2410(dot)org!