Question

I have a git clone/repo on a development server, but I am now moving to another one. I don't want to commit all my local branches and changes to the main repository, so how can I make an exact copy of everything on oldserver to newserver?

I tried oldserver:~$ scp -rp project newserver:~/project

but then I just get loads and loads of "typechange" errors when trying to do anything on newserver.

Someone said something about x-modes, but how can I preserve that when moving files between servers?

Was it helpful?

Solution

If you want a git solution, you could try

git clone --mirror <oldurl> <newurl>

though this is only for bare repositories.

If this is a non-bare repo, you could also do the normal clone, followed by something like this:

git fetch origin
git branch -r | grep '^ *origin/[^ ]*$' |
    while read rb; do git branch --no-track ${rb#*/} $rb; done
git remote rm origin

The middle step can of course be done in 5000 different ways, but that's one! (note that the continuation line \ isn't necessary after the pipe in bash - it knows it needs more input)

Finally, I'd suggest using rsync instead of scp (probably with -avz options?) if you want to directly copy. (What exactly are these typechange errors?)

OTHER TIPS

I've actually done this, and all I did was tar the repo up first and scp it over. I would think that scp -rp would work as well.

"Typechange" would normally refer to things like a symlink becoming a file or vice-versa. Are the two servers running the same OS?

You may also want to try the simple dumb solution -- don't worry about how the typechanges got there, but let git fix them with a reset command:

git reset --hard HEAD

That only makes sense if (1) the problems all pertain to the checked-out files (and not the repository structure itself) and (2) you haven't made any changes on newserver which you need to preserve.

Given those caveats, it worked for me when I found myself with the same problem, and it doesn't require you to think about git's internals or how well your file-transfer process is preserving attributes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top