简体   繁体   English

git push origin HEAD 是什么意思?

[英]What does git push origin HEAD mean?

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.一种将当前分支推送到遥控器上相同名称的便捷方法。

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 question seems to treat the problem, but the title is misleading).我一直没能找到答案( 这个问题似乎解决了这个问题,但标题有误导性)。

HEAD points to the top of the current branch. HEAD指向当前分支的顶部。 git can obtain the branch name from that. git可以从中获取分支名称。 So it's the same as:所以它是一样的:

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.如果要推送与当前分支不同的分支,该命令将不起作用。

If you want to push into the specific remote branch you can run:如果要推送到特定的远程分支,可以运行:

git push origin HEAD:<name-of-remote-branch>

This is what I encounter when I was trying to push my repo back to the remote branch.这就是我在尝试将 repo 推回远程分支时遇到的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM