Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between git push origin HEAD and git push origin [current-branch-name]?

Tags:

git

push

It looks like both accomplish the same task to me.
Are there cases in which they are different?

What is the difference between:
git push origin HEAD
git push origin [current-branch-name]

like image 505
Alexander Suraphel Avatar asked Nov 07 '14 11:11

Alexander Suraphel


People also ask

What is the difference between git push origin and git push origin?

Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin. Behavior could be changed via git config.

What is the difference between origin and head in git?

HEAD is a reference to the last commit in the currently checked out branch. The commit with HEAD->master is what the local master branch is pointing to. origin/master refers to the remote master branch. Once you push the commit to the remote must branch, Git will indicate that origin/master has the commit.

What is the difference between branch and origin branch?

Here, branch_name is a local branch, whereas origin/branch_name is a remote-tracking branch; it reflects the state of the corresponding branch that lives in origin .

What does git push origin branch name do?

To push the branch or you can say to push the changes in the branch to the Github repo you have to run this command “git push origin <the branch name>” in our case the branch name is “main”. After pushing the changes the repo will look like and this is how you can push a branch to a remotely hosted GitHub repository.


1 Answers

They mean exactly the same, since HEAD points to the tip of the current branch. See this answer for reference.

EDIT:

The only case in which this would not give the same result is when you are in detached HEAD state; but in that case, what is your definition of [current-branch-name]?

like image 183
Chris Maes Avatar answered Sep 28 '22 16:09

Chris Maes