This project is an example of how to use CircleCI to automatically mirror a Github repository to another remote. CircleCI offers a free-tier which is sufficient for this use-case.
- Copy circle.yml from this project into your repository root.
- Change the
GIT_MIRROR_URL
variable to the destination git remote URL. - Commit the file to your repo and push to github.
- Sign in to CircleCI, authorize it to access Github if asked.
- Go to "Add Projects" in the sidebar.
- Choose your Github user or organsation which owns the repo.
- Click the "Build project" button for the repo.
This first build will likely fail as there is no authentication credentials set up yet - see the next section.
This example will only cover SSH key authentication.
- Generate a new SSH key, eg
ssh-keygen -t rsa -C "reponame-mirror" -f ./reponame-id_rsa
- Go to the CircleCI dashboard, hover over the repository, and click on the cog icon.
- Go to the "SSH Permissions" tab.
- Copy the newly created private key and paste into the "Private key" field, eg
pbcopy < ./reponame-id_rsa
- Set the "Hostname" field to the hostname of the destination git remote.
- Copy the newly created SSH public key, eg
pbcopy < ./reponame-id_rsa.pub
- Add this public key to the destination remote. This process will depend on the system which manages the destination repository. For example:
- A deploy key with write access to the destination project (ie, another github repo).
- A ssh key for a specific user with write permission to the repo (ie, bitbucket as they dont have write access for deploy keys)
- An entry in
~/.ssh/authorized_keys
for custom git setups.
- Return to the CircleCI project, find the previously failed build and click "rebuild".
At this point you should have a working system!
To demonstrate this approach, this project uses CircleCI to mirror the GitHub repo to Bitbucket. The CircleCI build history can be viewed here - https://circleci.com/gh/nicksantamaria/git-mirroring-circleci