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:
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With