Search code examples
gitversion-controlgit-branchgit-pull

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?

Solution

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