A GitHub Action for updating a GitHub mirror repository.
- Updated GitHub mirror repository
- GitHub action can be triggered on a timer or on push (branches and tags)
Please see the SSH Step-by-Step Guide for step-by-step instructions using SSH.
Always make a full backup of your repo (
git clone --mirror
) before using this action.
# .github/workflows/git-sync.yml
on: push
jobs:
git-sync:
runs-on: ubuntu-latest
steps:
- name: git-sync
uses: dmejiar/git-sync@v1
with:
source_repo: "git@github.com:source-org/source-repo.git"
destination_repo: "git@github.com:destination-org/destination-repo.git"
source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }}
destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }}
You can use GitHub repo shorthand like username/repository.git
.
The
ssh_private_key
, orsource_ssh_private_key
anddestination_ssh_private_key
must be supplied if using ssh clone urls.
source_repo: "git@github.com:username/repository.git"
or
source_repo: "git@gitlab.com:username/repository.git"
The
ssh_private_key
,source_ssh_private_key
anddestination_ssh_private_key
can be omitted if using authenticated https urls.
source_repo: "https://username:personal_access_token@github.com/username/repository.git"
You only need to set up deploy keys if the repository is private and the ssh clone url is used.
- Either generate different SSH keys for both source and destination repositories or use the same one for both, leave the passphrase empty (note that GitHub deploy keys must be unique for each repository)
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-
In GitHub, either:
- Add the unique public keys (
key_name.pub
) to Repo Settings > Deploy keys for each repository respectively and allow write access for the destination repository
or
- add the single public key (
key_name.pub
) to Personal Settings > SSH keys
- Add the unique public keys (
-
Add the private key(s) to Repo > Settings > Secrets for the repository containing the action (
SSH_PRIVATE_KEY
, orSOURCE_SSH_PRIVATE_KEY
andDESTINATION_SSH_PRIVATE_KEY
)
You can run this in Docker locally for testing and development.
$ docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) \
$SOURCE_REPO $DESTINATION_REPO