0

I made a new branch a while back and now my git origin and master don't follow my HEAD.

Before this commit all of the following were on the current commit (HEAD -> BranchName), origin/master, origin/HEAD, origin, master, HEAD but after my commit on HEAD -> BranchName moved to the new commit. How do I resolve this for future commits and link all this together? This causes an issue when I push origin master to my repo because they are still on a previous commit.

Marcus
  • 9,032
  • 11
  • 45
  • 84
  • 1
    Remote branches don’t automatically follow when you commit changes locally. That’s what pushing is for. If that doesn’t help, please show an output of git log. – poke Jun 25 '15 at 18:19

1 Answers1

2

This is working as expected. When you make a commit locally, only your local branch will advance to the new commit. In your case origin/BranchName is there to mimic what is on the server; since you have not pushed yet, the server does not have your changes. After you do a git push, origin/BranchName will point to the same commit as BranchName.

Note that neither master nor origin/master will move, however, since you are not on that branch. If you want master to have the changes you made, you would need to merge BranchName into master.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • I have branches, but immediately before my commit, I am on the "master" branch but I still leave the master behind and the HEAD of the new commit is detached. To get around this, I have been deleting the master branch and then recreating it on my current commit (according to this SO post: http://stackoverflow.com/questions/26570242/how-to-move-master-to-head). I would prefer master move with my commit if I'm already on master when I commit. Is that possible or working as expected? – MrMas Mar 06 '17 at 15:58
  • @MrMas, If your commit does not move `master` forward, then you were not on `master` when you made your commit, i.e. your `head` was already detached. Perhaps you were on `origin/master` instead? – David Deutsch Mar 06 '17 at 21:24
  • Though I may be mistaken, I'm comfortable saying that what you say is not consistent with my experience. I did a couple commits. Then I checked out "master" and merged to the later commits. This "fast-forward" operation seems to have fixed things. I couldn't merge to master (it always told me it was up-to-date) but the reverse did the trick. – MrMas Mar 14 '17 at 23:30
  • 1
    @MrMas: Hmm, that is really odd. So before you do your commits, `git status` shows that you are on `master`? After a commit, which branch does `git status` show you are on? The behavior you describe would match being in a 'detached head' state before you made your commits, not just after. – David Deutsch Mar 15 '17 at 14:22
  • The short answer is that I wasn't actually checked out to "master". I'm still sort of new to Git (I'm more familiar with Hg) and although the commit I was on was named master, I did not check out "master" after going to a detached state. I did not appreciate that just setting a commit to a branch name (in this case, "master") doesn't automatically mean I'm checked out to that branch. – MrMas Apr 03 '17 at 16:01