将当前分支推到远程。

时间:2020-11-29 23:46:13

Is there a way in git bare repository to push a branch that is not in HEAD right now?

在git裸库中是否有一种方法来推动一个现在不存在的分支?

For example i have two branches:

例如,我有两个分支:

$ git branch
* master
  another

And i have two remotes set: origin and another.

我有两个遥控器:原点和另一个。

I need to be able push from another to another/another just in one command without changing HEAD.

我需要能够在一个命令中从另一个移动到另一个,而不需要改变头部。

2 个解决方案

#1


11  

With git push you can specify the remote and the local

使用git push,您可以指定远程和本地。

git push remotename branchname

#2


25  

All those "another another" in the original question, the answer and lots of comments are so confusing (which is a perfect example of why it is important to name your things right in the first place), I can't help helping (pun not intended) to write yet another answer as below.

在最初的问题中,所有那些“另一个”,答案和大量的评论都是令人困惑的(这是一个很好的例子,说明为什么要把你的东西命名为正确),我不能帮助(pun不打算)写下另一个答案。

Q: Is there a way in git (bare) repository to push a branch that is not in HEAD right now? For example i have two branches and two remotes. I need to be able push from feature to upstream/feature just in one command without changing HEAD.

问:在git(裸)存储库中是否有一种方法来推动一个现在不存在的分支?例如,我有两个分支和两个遥控器。我需要能够在一个命令中从特性到上游/特性,而不需要改变头部。

$ git branch
* master
  feature
$ git remote
origin
upstream

A: Do this.

答:这样做。

$ git push upstream feature

Q: Does it mean that it will push local feature to upstream/feature? I always thought it will push current HEAD to upstream/feature.

问:这是否意味着它将把本地特性推到上游/特性?我一直以为它会把现在的头推到上游/特写。

A: Yes. The feature part is a refspec, which, in general, has the form src:dst. This means to push the local branch src to the remote branch dst. If :dst is omitted, the local branch src is pushed to the remote branch src. You can specify a different name as remote branch too. Just do:

是的。特征部分是一个refspec,一般来说,它具有src:dst。这意味着将本地分支src推到远程分支dst。如果省略dst,则将本地分支src推到远程分支src。您也可以指定一个不同的名称作为远程分支。只做:

$ git push upstream feature:cool_new_feature

(Thanks @gabriele-petronella and @alexkey for providing materials for this answer.)

(感谢@gabriele-petronella和@alexkey为这个答案提供资料。)

#1


11  

With git push you can specify the remote and the local

使用git push,您可以指定远程和本地。

git push remotename branchname

#2


25  

All those "another another" in the original question, the answer and lots of comments are so confusing (which is a perfect example of why it is important to name your things right in the first place), I can't help helping (pun not intended) to write yet another answer as below.

在最初的问题中,所有那些“另一个”,答案和大量的评论都是令人困惑的(这是一个很好的例子,说明为什么要把你的东西命名为正确),我不能帮助(pun不打算)写下另一个答案。

Q: Is there a way in git (bare) repository to push a branch that is not in HEAD right now? For example i have two branches and two remotes. I need to be able push from feature to upstream/feature just in one command without changing HEAD.

问:在git(裸)存储库中是否有一种方法来推动一个现在不存在的分支?例如,我有两个分支和两个遥控器。我需要能够在一个命令中从特性到上游/特性,而不需要改变头部。

$ git branch
* master
  feature
$ git remote
origin
upstream

A: Do this.

答:这样做。

$ git push upstream feature

Q: Does it mean that it will push local feature to upstream/feature? I always thought it will push current HEAD to upstream/feature.

问:这是否意味着它将把本地特性推到上游/特性?我一直以为它会把现在的头推到上游/特写。

A: Yes. The feature part is a refspec, which, in general, has the form src:dst. This means to push the local branch src to the remote branch dst. If :dst is omitted, the local branch src is pushed to the remote branch src. You can specify a different name as remote branch too. Just do:

是的。特征部分是一个refspec,一般来说,它具有src:dst。这意味着将本地分支src推到远程分支dst。如果省略dst,则将本地分支src推到远程分支src。您也可以指定一个不同的名称作为远程分支。只做:

$ git push upstream feature:cool_new_feature

(Thanks @gabriele-petronella and @alexkey for providing materials for this answer.)

(感谢@gabriele-petronella和@alexkey为这个答案提供资料。)