Skip to content

Instantly share code, notes, and snippets.

@mtilson
Last active April 7, 2020 09:08
Show Gist options
  • Save mtilson/b329105c5ac50e6ed3bed096afcdb656 to your computer and use it in GitHub Desktop.
Save mtilson/b329105c5ac50e6ed3bed096afcdb656 to your computer and use it in GitHub Desktop.
how to mirror a GitHub repo [github]
# we are going to fetch all branches and tags from GitHub
# repo 'repo-to-fetch' and push them to GitHub repo 'repo-to-push'
# - 'repo-to-fetch' is supposed to be public available GitHub repo
# under the user account 'public-acc'
# - 'repo-to-push' is newly created GitHub repo the user account
# 'push-acc' has write access to
# create dir and init it as bare git repo
mkdir bare-repo
cd bare-repo
git init --bare
# configure 'repo-to-fetch' remote, see [1] for issue with
# GitHub 'refs/pull/*' refs
git remote add --mirror=fetch repo-to-fetch https://github.com/public-acc/repo-to-fetch
git config --unset-all remote.repo-to-fetch.fetch
git config --add remote.repo-to-fetch.fetch "+refs/heads/*:refs/heads/*"
git config --add remote.repo-to-fetch.fetch "+refs/tags/*:refs/tags/*"
# configure 'repo-to-push' remote
git remote add --mirror=push repo-to-push https://github.com/push-acc/repo-to-push
git config --add remote.repo-to-push.skipDefaultUpdate true
# configure user name and email used to push to 'repo-to-push' remote
git config user.email [email protected]
git config user.name push-acc
# fetch updates from 'repo-to-fetch' remote ('repo-to-push'
# remote skipped with help of 'skipDefaultUpdate')
git remote update # run the command any time you'd like to fetch updates
# push data to 'repo-to-push' remote
git push repo-to-push # run the command any time you'd like to push
# updates obtained with the above 'fetch'
# [1] http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment