Skip to content

kavindur/github-mirror-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Clone the repo

git clone <url>

Set seperate fetch and push URLs.

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

Verify

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)

Mirror Content

Generate and add ssh keys

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

Mirror using Script

#!/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

Sample ssh config in User/Developer Host

Windows (C:\Users\User.Name\.ssh\config)

# 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

Unix ( ~/.ssh/config)

# 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published