How should I move a hosted git repo to a new host?

2019-06-02 04:18发布

问题:

I have a TFS hosted git repo (e.g. https://tfsfoo.com/_git), and I need to move it to another TFS host (e.g. https://tfsbar.com/_git)

My solution is to do the following (modified based on suggestion below to use --mirror):

  1. git clone https://tfsfoo.com/_git/proj --mirror
  2. Loop through branches (git branch -r) and then git branch --track each of those (as in this post)
  3. Note that I had already pushed to the new repo (without branches), so --mirror wasn't an option.
  4. git pull
  5. git remote set-url origin https://tfsbar.com/_git/proj
  6. git push --all --follow-tags

Now - I know I can just try this to see if it works (and I probably will while I wait for answers), but given that there are multiple ways to do just about everything in git, I'm wondering if there's a better way - or more importantly, if there's anything wrong with this approach (I'm relatively new to git).

回答1:

Since you have network access to the second server, then yes, pushing is the easiest way.

To create local branches for all remote tracking branches, you can use the one-liner I usually use at "git pull all branches from remote repository".

The alternative is to git clone --mirror the first repo, and push it to the second server as in this answer.



回答2:

You can achieve this with git-copy.

git copy https://tfsfoo.com/_git https://tfsbar.com/_git


标签: git tfs