What does git push origin HEAD mean?

GitGit Push

Git Problem Overview


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).

Git Solutions


Solution 1 - Git

HEAD points to the top of the current branch. git can obtain the branch name from that. 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.

Solution 2 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question0x5C91View Question on Stackoverflow
Solution 1 - Githek2mglView Answer on Stackoverflow
Solution 2 - GitSarvar KhalimovView Answer on Stackoverflow