Maor Magori
Maor Magori

Reputation: 75

Copying a git repo to a different network

My project's git repo is currently located on my org's local network. The org asked me to move the project's repo to a different local network. My goal is to keep all of the all the commit's history and branches and not just copy-paste the files to a new repo.

Both networks have a GitLab clone on them if it helps somehow.

How can I achieve this?

Any help would be much appreciated.

Upvotes: 1

Views: 269

Answers (1)

mnestorov
mnestorov

Reputation: 4494

There are a couple of ways to move a local repository to a new location:

  1. Using simple copy-paste

This won't hurt you since, as long as you copy your .git folder properly. Git won't get confused if you move it to a new place since it has a "relative" notion of where the project is. However, in the unlikely event of you having git version 1.7.8 or 1.7.9 AND also have submodules in your project, then you should be careful with this method, as it may lead to problems. Read more about it here.

  1. Using git clone --mirror

This is a more "git" way of doing things. As described in the documentation

--mirror

Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.

  1. Using git bundle

This is another "git" way of doing this. This would produce a single file that you can later move to your new destination and apply it there. If in your case, you don't have a repo at the new destination, I suggest you follow the answer from VonC about moving everything with git bundle.

You would want to do something like

$ git bundle create /tmp/foo master
$ git bundle create /tmp/foo-all --all
$ git bundle list-heads /tmp/foo
$ git bundle list-heads /tmp/foo-all

I think the easiest is to just copy-paste your project if you have easy access to the new location.

Upvotes: 2

Related Questions