Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull origin HEAD

I was taught that you could push to and pull from a remote branch matching the name of your current Git branch by doing:

git push origin HEAD 

or

git pull origin HEAD 

Its always worked for me before, but it strangely doesn't work sometimes, instead deferring to push/pulling from the master branch instead (which causes a merge on pull... not what I want to do). I know that you can easily push/pull from the branch you're on by simply using the name of the branch like:

git pull origin name-of-branch-i-want-to-pull-from 

Anyway:

  1. Is there some reason that the HEAD is losing track/not pointing to my current branch, like it almost always does?
  2. Is there any way to push/pull to the branch that I'm currently working on (as long as the remote branch's name matches) without explicitly naming the branch in the command?
like image 469
Rican7 Avatar asked Sep 21 '12 14:09

Rican7


People also ask

What is git pull origin head?

HEAD here means the default branch on your local repository. However, when you do: git pull origin HEAD. HEAD here means the default branch on your remote repository. These 2 HEADs can have the same branch name, but very often they are different.

How do I point my head to the origin?

If you want to fix this, use git remote set-head origin -a , which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.

How do I pull a git branch from Origin?

In case you are using the Tower Git client, pulling from a remote is very easy: simply drag the remote branch and drop it onto your current HEAD in the sidebar - or click the "Pull" button in the toolbar.

Is git pull and git pull origin master same?

Remember, a pull is a fetch and a merge. git pull origin master fetches commits from the master branch of the origin remote (into the local origin/master branch), and then it merges origin/master into the branch you currently have checked out.


1 Answers

Thanks to some serious help by @abackstrom, I was able to fix my issue. Essentially, this post was my problem, and solution:

Git branch named origin/HEAD -> origin/master

The exact command to "recreate"/track a local HEAD branch/pointer correctly was:

git remote set-head origin -a 

I hope this helps anyone else that runs into this issue.

like image 161
Rican7 Avatar answered Sep 19 '22 23:09

Rican7