如何将我的远程git仓库移动到另一个远程git仓库?

时间:2013-01-21 03:43:05

标签: git git-remote

我想将远程git存储库及其所有分支移动到新的远程存储库。

old remote = git@github.com:thunderrabbit/thunderrabbit.github.com.git

new remote = git@newhub.example.net:tr/tr.newrepo.git

3 个答案:

答案 0 :(得分:12)

在本地计算机的终端中:

cd ~
git clone <old-remote> unique_local_name
cd unique_local_name

for remote in `git branch -r | grep -v master `; \
do git checkout --track $remote ; done

git remote add neworigin <new-remote>
git push --all neworigin

答案 1 :(得分:3)

整个想法是为每个旧的远程分支做:

  • 结帐
  • 推送到新的遥控器(不要忘记标签!)

就像那样:

#!/bin/bash

new_remote_link=git@newhub.example.net:tr/tr.newrepo.git
new_remote=new_remote
old_remote_link=git@github.com:thunderrabbit/thunderrabbit.github.com.git
old_remote=origin

git remote add ${old_remote} ${old_remote_link}

git pull ${old_remote}

BRANCHES=`git ls-remote --heads ${old_remote}  | sed 's?.*refs/heads/??'`

git remote add ${new_remote} ${new_remote_link}

for branch in ${BRANCHES}; do
    git checkout ${branch}
    git pull ${old_remote} ${branch}
    git push ${new_remote} ${branch} --tags
    printf "\nlatest %s commit\n" ${branch}
    git log --pretty=format:"(%cr) %h: %s%n%n" -n1
done

答案 2 :(得分:0)

您只需更改origin存储库的网址:

git clone <old-remote-url> unique_local_name
cd unique_local_name
git pull --all

git remote set-url origin <new-remote-url>
git push --all