git clone <url>
git remote set-url origin git@github.com:kavindur/github-mirror-test.git
git remote set-url --push origin ssh://git@scm.devops.cambio.se/~kavindu.ranasinghe/github-mirror-test.git
git remote -v
This should return an output like below
origin git@github.com:kavindur/github-mirror-test.git (fetch)
origin ssh://git@scm.devops.cambio.se/~kavindu.ranasinghe/github-mirror-test.git (push)
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_github -N ""
-
Go to https://github.com/settings/keys or repo → Settings → Deploy keys
-
Click "New SSH key" or Add deploy key
-
Title: something like sync-server-key / mirror-push
-
Paste the public key into the field
-
Click Add SSH key / Add key
#!/bin/bash
set -e
WORKDIR="repo-mirror"
BITBUCKET_REPO="ssh://git@scm.devops.cambio.se/~kavindu.ranasinghe/github-mirror-test.git"
GITHUB_REPO="git@github.com:kavindur/github-mirror-test.git"
# CLEANUP
rm -rf "$WORKDIR"
# CLONE FROM BITBUCKET
echo "[INFO] Cloning from Bitbucket..."
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_bitbucket -o IdentitiesOnly=yes"
git clone --mirror "$BITBUCKET_REPO" "$WORKDIR"
cd "$WORKDIR"
# SET PUSH REMOTE TO GITHUB
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_github -o IdentitiesOnly=yes"
git remote set-url --push origin "$GITHUB_REPO"
# PUSH TO GITHUB
echo "[INFO] Pushing to GitHub..."
git push --mirror
echo "[SUCCESS] SSH-based mirror sync completed."
Github repo should only be written from service accounts, users should not be allowed to write to that repo
# GitHub
Host github.com
HostName github.com
User git
IdentityFile C:\Users\User.Name\.ssh\id_github
IdentitiesOnly yes
# Bitbucket
Host scm.devops.cambio.se
HostName scm.devops.cambio.se
User git
IdentityFile C:\Users\User.Name\.ssh\id_bitbucket
IdentitiesOnly yes
# GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_github
IdentitiesOnly yes
# Bitbucket
Host scm.devops.cambio.se
HostName scm.devops.cambio.se
User git
IdentityFile ~/.ssh/id_bitbucket
IdentitiesOnly yes