Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer "authoritative" git repository from Github to a private github

Tags:

git

github

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?

like image 849
Mojo Avatar asked Apr 27 '12 05:04

Mojo


People also ask

How do I transfer a GitHub repository to another account?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under "Danger Zone", click Transfer. Read the information about transferring a repository, then type the name of the user or organization you'd like to transfer ownership of the repository to.

Can you deploy a private GitHub repo?

To register the repository SSH key with your private repository on GitHub, go to the Settings for the repository. On GitHub the repository SSH key is referred to by the term Deploy key. Search down the settings page and find the Deploy keys section and select it. Click on the Add deploy key button.


1 Answers

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.

like image 53
Rudi Avatar answered Nov 10 '22 16:11

Rudi