Skip to content

πŸ”„ Mirror GitLab, SourceForge, GitHub, and other Git repositories

License

Notifications You must be signed in to change notification settings

actions4git/mirror

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mirror Git repository

πŸ”„ Mirror GitLab, SourceForge, GitHub, and other Git repositories

Example mirror

😡 You don't even need to use a GitHub Action!
πŸ”Ά Use native Git commands to mirror a repository
:octocat: Works with any Git repository!

Usage

GitHub Actions Git

πŸ’‘ 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! 🀣

Mirror from GitHub to GitLab

GitHub GitLab

# 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.

Mirror from GitLab to GitHub

GitLab GitHub

# 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 }}

⚠️ We are using a third repository. Why? If we stored our workflow in the destination repository on GitHub it would be overwritten by the incoming 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.

Mirror from SourceForge to GitHub

SourceForge GitHub

# 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 }}

⚠️ We are using a third repository. Why? If we stored our workflow in the destination repository on GitHub it would be overwritten by the incoming 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.