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.
Answer from hek2mgl on Stack OverflowHEAD 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.
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.
git push origin head? - Stack Overflow
How to "git push origin HEAD:refs/for/master " for Gerrit repo in Sublime Merge
what is the difference between remotes/origin/HEAD and remotes/origin/master ?
What is “git push origin master?”
Videos
This is the Master branch. The main tree of your control system.
push = push your changes to the remote server
origin = remote Server origin
master = Master branch
If you have another remote branches you have something like "git push origin test" then you push your changes to the test remote branch.
That master is the <src> part of a refspec.
This means that your local master branch will be pushed to the master branch of the remote origin (orgin/master).
If you would have specified
git push origin master:my_work
then you would have pushed your local master to origin/my_work.
If you don't use the :my_work part, then the destination defaults to the same branch as given as source.
Just specifying
git push origin
will push every local branch that has a matching remote branch to that branch per default. Not just the current branch.
This is the same as using git push origin :.
You can change this default with git config remote.origin.push HEAD,
which would push the current branch to a remote branch with the same name.
See configure-a-local-branch-for-push-to-specific-branch for further details on configuring refspecs and setting push.default.