Matt Frear
Matt Frear

Reputation: 54811

Git: how to migrate all local repos to another machine?

I have code files from dozens of git repos in various subfolders under c:\code folder - 16Gb.

I want to migrate this folder to another computer. It's currently taking > 1 day to copy the entire folder to a USB drive, because it is around 650,000 small files.

Is there some script I can run to cleanup all of the repos in my c:\code folder?

Edit: all of the repos have a remote. I don't care about copying all branches. I only care about keeping the directory structure of the repos, i.e.

c:\code\github\NLog
c:\code\github\Swashbuckle.AspNetCore
c:\code\myclient\DevOpsProject1\solution1
c:\code\myclient\DevOpsProject1\solution2
c:\code\myclient\DevOpsProject2\solutionx
etc

Upvotes: 2

Views: 372

Answers (3)

Matt Frear
Matt Frear

Reputation: 54811

What I was originally looking for:

find . -name .git -type d -execdir git clean -dxf \;

This cleaned up my 16Gb of files across all repositories down to 800Mb. And then @VonC's answer (N.B remove v option from the below to be quieter)

tar cpvf code.tar code

and then on the destination machine:

tar xpvf code.tar

Whenever I would use git in the copied folders, I then kept getting errors:

fatal: detected dubious ownership in repository

So to fix that I had to "Take ownership" of the folder. I'm on Windows, which meant Properties of the code folder -> Security -> Advanced -> Owner -> Change. Even though "Local administrators" owned the folder, and I am a member of that group, I had to make myself the owner.

An additional hurdle was because I'm on a corporate machine I couldn't see the Security tab. Here's the fix for that.

Upvotes: 1

VonC
VonC

Reputation: 1324013

You can use git bundle to bundle each of the repositories full history into one file (per repository)

And you can zip the dozen of bundle into a giant tar file.

Result: only one (big) file to copy, and to untar.

You can then clone back your repositories from their respective bundle (cloning them from their bundle file).


I don't care about copying all branches. I only care about keeping the directory structure of the repos

The, an alternative approach is to simply tar cpvf code.tar code under C:\.
Copy the giant tar file to the target machine, and tar xpvf code.tar: the directory structure will be preserved.

A bit as in here:

find . -name "*.git" -type d -exec tar -czf {}.tar.z {} \; -exec rm {} \;

(Be careful with the -exec rm part: test it out first).

Upvotes: 2

hyphens2
hyphens2

Reputation: 166

You clone only lasted commit from your remote repository like

git clone --depth 1 https://url-of-your-repo

Upvotes: -2

Related Questions