我想将我的远程git存储库及其所有分支移动到新的远程存储库。如何将我的远程git仓库移动到另一个远程git仓库?
老远程= [email protected]:thunderrabbit/thunderrabbit.github.com.git
新的远程= [email protected]:tr/tr.newrepo.git
我想将我的远程git存储库及其所有分支移动到新的远程存储库。如何将我的远程git仓库移动到另一个远程git仓库?
老远程= [email protected]:thunderrabbit/thunderrabbit.github.com.git
新的远程= [email protected]:tr/tr.newrepo.git
所以这些其他答案都没有解释得太好,如果你想 移动你所有的远程仓库的br使用Git的push
机制,,然后您需要您的每个远程的 分支机构的本地分支版本。
您可以使用git branch
创建本地分支。这将在您的.git/refs/heads/
目录下创建分支 参考,其中存储了所有本地 分支参考。
然后你可以使用git push
与--all
和--tags
选项标志:
git push <new-remote> --all # Push all branches under .git/refs/heads
git push <new-remote> --tags # Push all tags under .git/refs/tags
注意--all
和--tags
不能一起使用,所以这就是为什么你必须 推两次。
下面是相关git push
documentation:
--all
命名每个裁判推相反的,指定
refs/heads/
下的所有裁判推。--tags
refs/tags
下,所有的裁判都推,除了refspecs在命令行中明确列出 。
--mirror
还要注意--mirror
可用于在 推一旦两个分支或标签引用,但有这个标志的问题是,它推动在 .git/refs/
,不所有引用只是.git/refs/heads
和.git/refs/tags
,这可能不是 你想推送到你的远程。
例如,--mirror
可以从旧 远程(一个或多个),它们.git/refs/remotes/<remote>/
下,以及其它参考文献 诸如.git/refs/original/
,这是git filter-branch
副产品推远程跟踪分支。
在本地计算机上的终端:
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
最后一行(git push --all gitlab)是否是一个错字?它不应该是新的起源,而不是gitlab? –
啊,是的,看起来像。谢谢! –
仅供参考,如果您想推送标签,那么您还需要使用'git push --tags'(它不能与'--all'同时使用)。另外,不要使用'git checkout',你也可以使用'git branch',这可能会更快,因为你不会在工作副本中切换文件。 – 2014-04-27 19:02:16
整个想法是每个老远程分支的更多信息:
就像是:
#!/bin/bash
[email protected]:tr/tr.newrepo.git
new_remote=new_remote
[email protected]: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
您可以简单地改变URL为您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
这是不正确的,如果您没有每个远程分支的本地分支版本,那么它们将不会被推送到新的远程。只有'.git/refs/heads /'下的本地分支才会被推送。 – 2014-04-27 18:52:28
我知道这是一个自我回答的问题,但问题本身质量仍然很低。也许尝试添加一些您尝试过的想法或在您提出[您的答案](http://stackoverflow.com/a/14432237/456814)之前查看过的文档。 – 2014-04-27 18:18:25
仅供参考,[umläute的回答](http://stackoverflow.com/a/14435630/456814)不完全正确,请参阅[我的评论](http://stackoverflow.com/questions/14432234/how-do-我 - 移动 - 我 - 远程混帐回购到另一个远程-混帐回购#comment35718703_14435630)。 – 2014-04-27 18:59:21