Your process is almost perfect. The only thing was a missing --mirror
parameter on the initial clone.
# create the private repo
ssh private-server
mkdir -p /path/to/shared/repos
git init --shared={whatever makes sense for your environment} /path/to/shared/repos/internalrepo.git
exit
# go to github.com and make the public repo readonly
# create a local mirror
git clone --bare --mirror $Github-URL github.git
# now the local repo github.git contains all the stuff from the github repo
cd github.git
git push --mirror $Private-URL
# Tell all developers to execute `git remote set-url origin $Private-URL`
# Done
I would not leave the github repo open for changes, since it would not be clear to everyone in the project which repo is now the correct repo. You can still do it, if you run on the server-repo
ssh private-server
cd /path/to/shared/repos/internalrepo.git
git remote add --mirror github $Github-URL
and then regularly (like in a cron job)
git fetch github # get new commits from github
git remote prune github # drop branches, which are now deleted in the github repo
Edit
You also can use the local mirror to do the exchange. But there is no easy automated process, since git can't decide neither what to do with deleted branches, nor what to do with diverged branches. Sou you need to keep a working repository where you regular fetch the stuff from the former github-repo, fetch the stuff from the internal repo, resolve diverging history and push this stuff back to the internal repo.