Mirroring to git repositories with Woodpecker CI

As part of my homelab, I have a local Forgejo instance to hold my repositories. But I still want to have a copy on external forges.

I don’t want to manage the copies manually. Thankfully, I can use my CI to push copies on the mirror repositories I have on github and codeberg.

Here’s how it’s done with woodpecker:

when:
  - event: [push, manual]
    branch: main

clone:
  git:
    image: alpine/git
    environment:
      GIT_SSL_NO_VERIFY: "true"
    commands:
      - git clone --mirror https://forgejo.local/[YOUR_USERNAME]/[REPO_NAME].git .git
      - git config --unset-all remote.origin.fetch
      - git config --bool core.bare false

steps:
  - name: mirror
    image: alpine/git
    environment:
      GITHUB_MIRROR_TOKEN:
        from_secret: github_mirror_token
      CODEBERG_MIRROR_TOKEN:
        from_secret: codeberg_mirror_token
    commands:
      - git remote add github https://x-token-auth:$GITHUB_MIRROR_TOKEN@github.com/[YOUR_USERNAME]/[REPO_NAME].git
      - git remote add codeberg https://x-token-auth:$CODEBERG_MIRROR_TOKEN@codeberg.org/[YOUR_USERNAME]/[REPO_NAME].git
      - git push --mirror github
      - git push --mirror codeberg

Summary

This is a simple but effective solution to manage multiple mirror for a git repository. These can now be easily shared with others, and also serve as additional backups.

Tags: