git push 分支到具有不同名称的新仓库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19105934/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:08:11  来源:igfitidea点击:

git push branch to a new repo with a different name

gitbranch

提问by Daniel Powell

How can I push a branch to a different repo with a new name for the branch.

如何使用分支的新名称将分支推送到不同的存储库。

For instance I have a branch feature1on repo abcand I'd like to push to repo xyzand make it the master branch.

例如,我feature1在 repo 上有一个分支abc,我想推送到 repoxyz并使其成为主分支。

I tried using Renaming remote git branchbut then after doing a git clone on the new repo I got the error message

我尝试使用Renaming remote git branch但在对新 repo 执行 git clone 之后我收到了错误消息

git Warning: remote HEAD refers to nonexistent ref, unable to checkout

git 警告:远程 HEAD 指的是不存在的 ref,无法结帐

Is there a way to specify in the push what I want the destination branch name to be?

有没有办法在推送中指定我想要的目标分支名称?

回答by 13ren

I think this should work:

我认为这应该有效:

git push xyz feature1:master

If master already exists, you can clobber it with -f/--force, or +:

如果 master 已经存在,您可以使用-f/--force, 或来破坏它+

git push -f xyz  feature1:master
git push    xyz +feature1:master

From the man page (in the examples section at the end):

从手册页(在最后的示例部分):

   git push origin +dev:master
       Update the origin repository's master branch with the dev branch,
       allowing non-fast-forward updates. [...]
   git push origin +dev:master
       Update the origin repository's master branch with the dev branch,
       allowing non-fast-forward updates. [...]