π Mirror GitLab, SourceForge, GitHub, and other Git repositories
π΅ You don't even need to use a GitHub Action!
πΆ Use native Git commands to mirror a repository
Works with any Git repository!
π‘ Try to provide a meta description somewhere on your mirrored repository's page to indicate that it's a mirror of another project and not the original source. You don't want people opening Issues or merge requests against your mirror! π€£
# octocat/my-project [source repository]
# .github/workflows/mirror.yml
name: Mirror
on:
push:
create:
delete:
workflow_dispatch:
jobs:
gitlab-myorg-my-project:
concurrency:
group: ${{ github.workflow }}-gitlab
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- run: git clone --bare "https://github.com/$GITHUB_REPOSITORY" .
- run: git push --mirror "https://x:[email protected]/myorg/my-project.git"
env:
GITLAB_TOKEN: ${{ secrets.MY_TOKEN }}
Make sure you create a GitLab personal access token with the permissions needed to write to the myorg/my-project Git destination repository. Then make sure you add the secret token value to the GitHub settings panel for the source repository.
If you're using a non-public GitHub repository you may need to use gh auth setup-git
to configure your credentials properly.
# octocat/.github [another third repository]
# .github/workflows/mirror.yml
name: Mirror
on:
schedule:
- cron: "36 */6 * * *"
workflow_dispatch:
jobs:
mirror1:
runs-on: ubuntu-latest
steps:
- run: git clone --bare https://gitlab.com/myorg/my-project.git .
- run: git push --mirror "https://x:[email protected]/octocat/my-project.git"
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
git push --mirror
. It's recommended to use a meta repository like
octocat/.github or myorg/.github to manage mirroring. You can use the same
workflow file for multiple mirroring jobs if you have multiple mirrors you want
to sync.
You'll need to create a GitHub personal access token with write permissions to the contents of the octocat/my-project GitHub repository and then add the secret GitHub token to your third repository that will manage the scheduled syncing.
# octocat/.github [another third repository]
# .github/workflows/mirror.yml
name: Mirror
on:
schedule:
- cron: "36 */6 * * *"
workflow_dispatch:
jobs:
mirror1:
runs-on: ubuntu-latest
steps:
- run: git clone --bare https://git.code.sf.net/p/myorg/my-project .
- run: git push --mirror "https://x:[email protected]/octocat/my-project.git"
env:
GITHUB_TOKEN: ${{ secrets.MY_TOKEN }}
git push --mirror
. It's recommended to use a meta repository like
octocat/.github or myorg/.github to manage mirroring. You can use the same
workflow file for multiple mirroring jobs if you have multiple mirrors you want
to sync.
You'll need to create a GitHub personal access token with write permissions to the contents of the octocat/my-project GitHub repository and then add the secret GitHub token to your third repository that will manage the scheduled syncing.