6

My task is to move our repositories from public github to a private instance of github on our local net.

My thought is to move them with

git clone --bare <github-repo-url>
git push --mirror <local-github-url>

During a transition time, I should be able to make the mirror update itself from the repository on the daddy github. (Or will I? I haven't found a command in the UI to do an update.)

Then I will delete the "authoritative" github repository, and the mirror will become authoritative.

But how does that happen? Does each developer need to change the url for "origin" in .git/config?

Will the mirror accept pushes that aren't updates from its clone-parent?

Mojo
  • 2,687
  • 5
  • 30
  • 42
  • More information: The "local-github-url" is truly a Github. It's a private Github Enterprise service. I have no shell or crontab access to the private Github. – Mojo Apr 27 '12 at 21:09

2 Answers2

5

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.

Rudi
  • 19,366
  • 3
  • 55
  • 77
  • 1
    Rudi, great answer! However it assumes that the private repo is on a machine where I have shell/crontab. In my case the private repo is on a "Github Enterprise" instance that's inside a firewall. I have no direct access to the private repository except through git and the web site. – Mojo Apr 27 '12 at 21:06
  • I have yet to see a solution for GHE. Even some discussion on the GHE website was removed. – Shane Jan 02 '15 at 18:25
0

The simplest process would be for the developers to clone the new (private) repo and go on from there.
If they have any pending changes in progress in their former repo, they can export those as patches and apply them on the new locally cloned repo before pushing them back to the new origin. (See What is the difference between 'git format-patch' and 'git diff'? and git format-patch man)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250