Git pull origin HEAD

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.


The thing is, when you do:

git push 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.

For example, if the default branch of your local repository and remote repository are both master, then you switched to a new branch feature on local repository, then pushed it to remote by doing git push origin HEAD, the default branch on remote won't be changed to feature magically. Instead it will stay at master. At this point, if you do git pull origin HEAD on your feature branch, you are actually doing git pull origin master.

So I would suggest avoid doing git pull origin HEAD, because it's not obvious what's the default branch is on the remote, and can cause unexpected problems.


HEAD is not really a branch. It's a pointer to the commit that you currently have checked out, and will often reference a branch, but if you do something like git checkout <sha> or git checkout <tag>, then HEAD references a commit directly, with no tie to a branch - this is called a "detached HEAD" state, and you should normally get a warning from git checkout when you enter such a state. In that state, trying to push/pull HEAD doesn't make sense, since you're not on a branch.