git push origin HEAD 是什么意思?

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

What does git push origin HEAD mean?

gitgit-push

提问by scristalli

I found, in the official guide:

我在官方指南中发现:

git push origin HEAD

A handy way to push the current branch to the same name on the remote.

git push origin HEAD

一种将当前分支推送到遥控器上相同名称的便捷方法。

However, the meaning of the command is not clear to me. Why does it have this effect?

但是,我不清楚该命令的含义。为什么会有这种效果?

I haven't been able to find an answer (this questionseems to treat the problem, but the title is misleading).

我一直没能找到答案(这个问题似乎解决了这个问题,但标题有误导性)。

回答by hek2mgl

HEADpoints to the top of the current branch. gitcan obtain the branch name from that. So it's the same as:

HEAD指向当前分支的顶部。git可以从中获取分支名称。所以它是一样的:

git push origin CURRENT_BRANCH_NAME

but you don't have to remember/type the current branch name. Also it prevents you from pushing to the wrong remote branch by accident.

但您不必记住/键入当前的分支名称。它还可以防止您意外推送到错误的远程分支。

If you want to push a different branch than the current one the command will not work.

如果要推送与当前分支不同的分支,该命令将不起作用。