git 将所有分支从一个远程推送到另一个远程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37884832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git push all branches from one remote to another remote
提问by Tao Huang
I have two remote: upstream and origin. upstream is something I can't push to. origin is my own repo. How can I fetch all branches from upstream and then push them to origin? I tried:
我有两个远程:上游和原点。上游是我无法推动的。origin 是我自己的仓库。如何从上游获取所有分支,然后将它们推送到原点?我试过:
git fetch upstream
git push --all origin
But it doesn't work.
但它不起作用。
回答by Nicko Glayre
You may want to try cloning your upstream repo with --mirror
option and then push to your new remote with --mirror
option too
你可能想尝试克隆你的上游与回购--mirror
选项,然后推到新的遥控器,带--mirror
选项太多
You'll have the following flow:
您将拥有以下流程:
git clone <upstream-repo-url/repo.git> --mirror
cd <repo>
git remote add <your-remote-name> <your-remote-url/repo.git>
git push <your-remote-name> --mirror
回答by jose.arias
I just needed to copy one repository from Bitbucket to GitHub, these are the steps assuming your remote is called origin, all branches and tags will be copied:
我只需要将一个存储库从 Bitbucket 复制到 GitHub,这些步骤假设您的远程名为 origin,所有分支和标签都将被复制:
git remote add neworigin url-to-new-remote
git push neworigin --tags refs/remotes/origin/*:refs/heads/*
Good thing about this is that files in your working copy won't be modified.
这样做的好处是您的工作副本中的文件不会被修改。
回答by RobG
One complete answer of cloning from one (bare) repository to another (bare) repository taking ALL branches, not just the checked out ones, is to clone a local bare repository as an intermediary. Then all branches are pulled as part of the clone and a git push --all will push them all. Example performed on Windows from github to gitlab:
从一个(裸)存储库克隆到另一个(裸)存储库并采用所有分支(而不仅仅是签出的分支)的一个完整答案是克隆本地裸存储库作为中介。然后将所有分支作为克隆的一部分拉出,并且 git push --all 将全部推送它们。在 Windows 上从 github 到 gitlab 执行的示例:
- git clone --bare [email protected]:robe070/cookbooks.git
- cd cookbooks.git
- git remote add gitlab [email protected]:robe071/cookbookstest2.git
- git push --force --all gitlab
- git push --force --tags gitlab
- git clone --bare [email protected]:robe070/cookbooks.git
- cd 食谱.git
- git 远程添加 gitlab [email protected]:robe071/cookbookstest2.git
- git push --force --all gitlab
- git push --force --tags gitlab
Result: 25 branches pushed to gitlab
结果:25 个分支推送到 gitlab
Note, git checkout is not required for all the branches and meaningless to a bare repo anyway.
请注意,所有分支都不需要 git checkout 并且对裸仓库毫无意义。
回答by akhileshnair
Hope this helps:
希望这可以帮助:
git remote add your-new-origin url-to-repo/repo.git
git push --all your-new-origin //pushes all branches
git push --tags your-new-origin //pushes all tags