Skip to content
Tim Hårek's logo

How to mirror from SourceHut to GitHub

2 minutes read

Last year I started to use SourceHut for all my personal projects and I also use its build-system for my CI/CD. But I'm not ready to say goodbye to GitHub yet, we use GitHub at work and stuff like my Deno modules rely on GitHub. The way I mirrored some of my repos up until now is by having multiple push-urls, but when I go to another computer I have to remember to setup all of those urls again.

How to setup a mirror

There aren't that many steps involved, so I'll be breif:

  1. Initialize a repository on SourceHut, or use an existsing one.
  2. Generate a new SSH-key, example: ssh-keygen -t ed25519 -C "sourcehut"
  3. Copy the contents of your private key. On macOS: cat ~/.ssh/sourcehut | pbcopy
  4. Go to
  5. Add a new secret, give it a name "sourcehut ssh key", paste the private key in the secret field and specify that the secret is a "SSH key".
  6. Copy the hash of the generated secret.
  7. Add a new file to your repository, .build.yml.

Within your .build.yml, add the following:

image: alpine/edge
  - <your-hashed-secret>
  - git+ssh://<username>/<repo>
  - check: |
      cd <repo>
      if [ "$(git rev-parse origin/main)" != "$(git rev-parse HEAD)" ]; then \
        complete-build; \
  - mirror: |
      cd <repo>
      git remote add github<github_username>/<github_repo>.git
      ssh-keyscan -t rsa >> ~/.ssh/known_hosts
      git push github main

Remember to change:

  • <your-hashed-secret>
  • <username>
  • <repo>
  • <github_username>
  • <github_repo>

The check-task is there to ensure that we only mirror stuff commited to the main-branch, but this step is entirely optional – so you can remove that task if you want.