Last active
December 5, 2025 01:40
-
-
Save ebarooni/c268a88bf8e09175b5017a176f46b31e to your computer and use it in GitHub Desktop.
A GitHub workflow to mirror a repository to a different remote on push
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Mirror | |
| on: | |
| push: | |
| branches: | |
| # or restrict to a specific branch (e.g. main) | |
| - "**" | |
| jobs: | |
| mirror: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| run: | | |
| REPO_URL=$(echo "https://github.com/${{ github.repository }}" | sed "s|://|://x-access-token:${{ secrets.GITHUB_TOKEN }}@|g") | |
| git clone --bare $REPO_URL | |
| - name: Set git config | |
| run: | | |
| cd $(basename ${{ github.repository }}).git | |
| git config user.name ${{ github.event.pusher.name }} | |
| git config user.email ${{ github.event.pusher.email }} | |
| # replace * with your desired remote name (e.g. GITLAB) | |
| - name: Mirror to remote | |
| env: | |
| *_MIRROR_TOKEN: ${{ secrets.*_MIRROR_TOKEN }} | |
| run: | | |
| cd $(basename ${{ github.repository }}).git | |
| *_REPO=${{ secrets.*_REPO_URL }} | |
| git remote add * https://oauth2:${*_MIRROR_TOKEN}@${*_REPO#https://} | |
| git push --mirror * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment