Skip to content

Instantly share code, notes, and snippets.

@ebarooni
Last active December 5, 2025 01:40
Show Gist options
  • Select an option

  • Save ebarooni/c268a88bf8e09175b5017a176f46b31e to your computer and use it in GitHub Desktop.

Select an option

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