I always like to have a backup copy of all my important git repositories hosted on Github. I use a private repository at Gitlab to mirror each of these repositories. Currently, I have a Github Action workflow configured to copy it on any git push on any branches.

Github Action Workflow

Create a .github/workflows/mirror.yml in the Github repository with the follow contents.

name: Mirror to Gitlab

on: [push, delete]

    runs-on: ubuntu-latest
    - uses: actions/checkout@v1
    - uses: pixta-dev/repository-mirroring-action@v1
          ${{ secrets.GITLAB_SSH_KEY }}


Create an RSA key pair to allow the Github action runner to write to the Gitlab repository.

ssh-keygen -t rsa -b 2048 -C "<comment>"

Executing the command will create two files, one with a .pub extension which is the public key and one with no extension which is the private key.

Since I like to use a different set of key pair for each repository, I

Gitlab (Public Key)

Add a deploy key by navigating to Repository > Settings > Deploy Keys > Expand > Add Key. Fill the contents of .pub file or the public key here. Details at docs.gitlab.com.

IMPORTANT - Remember to check the Write access allowed option while adding the key

Github (Private Key)

Add a secret by navigating to Repository > Settings > Repository > Secrets > New Secret. Fill the contents of the private key and name as GITLAB_SSH_KEY. Details at docs.github.com.