我想将我的远程git存储库及其所有分支移动到新的远程存储库.
老遥远= git@github.com:thunderrabbit/thunderrabbit.github.com.git
新遥控= git@newhub.example.net:tr/tr.newrepo.git
Thu*_*bit 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
Run Code Online (Sandbox Code Playgroud)
小智 7
所以这些其他答案都没有解释的是,如果你想使用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
Run Code Online (Sandbox Code Playgroud)
请注意,--all
并且--tags
不能一起使用,这就是为什么你必须推两次.
这是相关git push
文档:
Run Code Online (Sandbox Code Playgroud)--all
而不是命名每个引用推送,指定所有refs
refs/heads/
被推.Run Code Online (Sandbox Code Playgroud)--tags
refs/tags
除了在命令行中明确列出的refspec之外,所有引用都被推送.
--mirror
还要注意,--mirror
可用于一次性推两个分支或标签引用,但这个标志的问题是,它推动所有引用的
.git/refs/
,而不仅仅是.git/refs/heads
和.git/refs/tags
,这可能不是你想要推到远程什么.
例如,--mirror
可以从您的旧遥控器推送远程跟踪分支.git/refs/remotes/<remote>/
,以及其他参考,例如.git/refs/original/
,副产品git filter-branch
.