3

I have a development host pats1 that has a GIT repo in a directory on the host:

~pats/gitrepos/myrepo.git 

The repo holds some personal scripts and development tools that I clone to other boxes (say host1 and host2) when I'm doing development on the other hosts. I just use ssh to clone and push updates; There is no github or "real server" being used.

My pats1 box died (hard disk VM was wiped out), and I'm wondering what steps to take to get a new replacement repo set up by using data from the existing copies.

I want to know what steps to take to convert one of the working git copies of myrepo on host1 or host2 and setup a pats2:gitrepos/myrepo.git to be the new central server and point the existing working repos (on host1 and host2) to the new server.

Questions similar to this have been asked. Some are:

How to migrate GIT repository from one server to a new one

Convert a normal repo to a bare one

Some of the answers given require the old server to be around which is not an option for me. Below are the steps I think I need to follow:

(1) Pick one of the hosts to create the new "central server (pats2)". Is one host better to use than the other?

For this example, I'll pick host1.

(2) Make sure the repo on host1 contains everything you want copied.

This post Atlassian Developer Tip of Week - Copying a full git repo says to do this the right way I would want to make sure the local repo has all of the branches of the remote/origin checked out so that when the repo is cloned, the branches are present.

Well, since my origin host (pats1) is not available, I might have some references to remote branches that are not checked out in the local repo. I believe this will automatically be cleaned up when I copy using git clone --mirror based on something I read but can't find the link to the article.

So for this step, I'm stuck with what I have in the repo on host1 which in my case is fine because I only have a master branch. :-)

This article how-to-properly-mirror-a-git-repository says I should delete non-existent references as well using:

git fetch --prune

NOTE: This failed when I tried it because it couldn't access the origin.

(3) Create a mirror of the repo on host1.

ssh host1; cd proj
git clone --mirror myrepo myrepo.git

I'm using --mirror because How to properly mirror a git repository says :

Also git clone --mirror is prefered over git clone --bare because the former also clones git notes and some other attributes.

(4) Copy that repo.git (repo) to my new server (pats2):

ssh pats2 mkdir gitrepos
scp -r myrepo.git pats2:gitrepos/

The above command puts it in the correct place (~pats/gitrepos/myrepo.git) so in the future I can clone it using the command

git clone pats2:gitrepos/myrepo

NOTE: If the repo were large I might want to tar with compression and untar to minimize network bandwith, for example tar czf - myrepo.git | mbuffer -s 1K -m 512 | ssh otherhost "cd gitrepos; tar zxf -"

(5) Point the existing hosts that have working copies of myrepo to point to the new repo location (on pats2)

ssh host1; cd proj/myrepo; 
git remote set-url origin pats2:gitrepos/myrepo.git

Repeat above command for all hosts that were using the old "central1" host (pats1).

I hope someone else finds this useful and others can confirm that what I'm planning to do will work.

PatS
  • 8,833
  • 12
  • 57
  • 100

1 Answers1

1

Your steps seem good.

On 5, you can simply do:

cd proj/myrepo
git remote set-url origin pats2:gitrepos/myrepo.git

That will change the URL associated with origin.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC for the improvement. I've updated my question to reflect this, and selected this as the answer. – PatS Oct 16 '17 at 21:41