Rui Gonçalves
Rui Gonçalves

Reputation: 2433

How to move git repositories from github to local server running gitolite

I would like to know the preferable way to move all my git repositories currently hosted on github to a new git server gitolite-based.

Just for knowing, the reason why I'm doing this switch is the adoption of Redmine to support our project management process.

Upvotes: 4

Views: 3504

Answers (5)

Raymond Tau
Raymond Tau

Reputation: 3469

With reference to this: http://gitolite.com/gitolite/basic-admin/#appendix-1-bringing-existing-repos-into-gitolite. How about:

  1. On the gitolite server, make a mirror of the github repositories with the command git clone --mirror <github git repo path>
  2. Move the mirror repo to the correct location as in the link above, then just follow the section moving existing repos into gitolite of the guide?

Upvotes: 5

starfry
starfry

Reputation: 9943

To mirror a GitHub repo onto Gitolite, first create a new repo on Gitolite (using the gitolite-admin repo - I'll assume the Gitolite admin knows how to do that), but here's an example config entry:

repo github/<gh-user>/<gh-repo>
desc = "Repository description [https://github.com/<gh-user>/<gh-repo>]"
owner = "My Name"
category = "GitHub"
RW+ = my_key

where <gh-user> is the GitHub user and <gh-repo> is the GitHub repository being mirrored. This example places the mirror within a GitHub and user subdirectory, but you can use any repo path that suits.

Then, from anywhere with access to both GitHub and Gitolite:

$ git clone --mirror https://github.com/<gh-user>/<gh-repo>
$ cd <gh-repo>.git
$ git push --mirror gitolite git@git:github/<gh-user>/<gh-repo>
$ cd ..
$ rm -rf <gh-repo>.git

where git@git is the SSH user and hostname used to connect to Gitolite. The local clone is temporary and is deleted afterwards.

The OP asked only about moving repositories, in which case he might stop here. However, should it be desirable to host a local mirror of a repo on GitHub and periodically synchronize the local mirror then here's a way to do that.

To sync the Gitolite mirror with GitHub, log on to the Gitolite server as the Gitolite admin (git) user and perfom the following configuration:

$ cd ~git/repositories/github/<gh-user>/<gh-repo>
$ git remote add origin https://github.com/<gh-user>/<gh-repo>
$ git config remote.origin.fetch "+*:*"

The parameters in the commands are explained clearly here.

Then, to sync the repo:

$ git fetch --prune

The fetch could be automated via a cron job.

Upvotes: 0

Per Christian Henden
Per Christian Henden

Reputation: 1585

Perhaps you also want to bring your tags to the new server. This can be done by

    git push --tags

Upvotes: 1

Tuxdude
Tuxdude

Reputation: 49473

Add the new repo in gitolite-admin/conf/gitolite.conf

repo my-new-repo
    RW+            = your-user

Add, commit and push the changes into gitolite-admin

git add conf/gitolite.conf
git commit -m "Added my-new-repo"
git push origin

Clone your github repo and checkout all the branches present

git clone github.com:/USERNAME/YOUR_REPO.git
cd YOUR_REPO
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do     git branch --track ${branch##*/} $branch; done

Remove the github remote, and add your gitolite remote:

git remote rm origin
git remote add origin YOURSERVER:my-new-repo.git

Push all the refs onto the repo managed by gitolite:

git push --all origin

I verified the steps in a test repository of mine, and all the refs seem to have propagated into the new repo.

UPDATE: Like Seth pointed out, any other refs other than branches are not propagated to the new repo. I too feel Mirror would be a better option.

Upvotes: 6

Isaac
Isaac

Reputation: 3616

The best thing I can think of would be to pull a local copy, change the origin to the new server, and then push:

git pull --all
git remote rm origin
git remote add origin <new repo address>
git push --all --repo=origin

Upvotes: 2

Related Questions