0

I've checked the remote branch Design0.5: the last remote commit on that branch is identical to the top local commit, here marked (no branch). So locally, Design0.5 is 5 commits behind where I'd like it to be; but also the remote branch remotes/origin/Design0.5 is shown as behind where it really is. That really puzzles me. All I really want to do here is track remote changes to the repository. How do I get to a state where I really am tracking Design0.5 as it is remotely? I could just give up and check out the branch somewhere else but there are untracked binary files in my local directory which I don't want to have to move; it might also help me understand git better if I can fix my local without resorting to that.

I've looked at the related query Why did git set us on (no branch)? and tried various suggestions there (such as the rebase) but without success.

My last 2 commands were

$ git pull --rebase origin Design0.5

$ git branch -av
* (no branch)              130bef1 Debugging Program.fs note point at which crash occurs
  Design0.3                f7f6179 Updated tests and comments
  Design0.5                578ff32 [behind 5] updated project to include new files
  master                   578ff32 [behind 5] updated project to include new files
  remotes/origin/Design0.1 f7f6179 Updated tests and comments
  remotes/origin/Design0.3 f7f6179 Updated tests and comments
  remotes/origin/Design0.5 f98e08e Added definition of FOO
  remotes/origin/master    578ff32 updated project to include new files

No doubt I do not properly understand how git branches work.

Community
  • 1
  • 1
fairflow
  • 445
  • 3
  • 12
  • How did you check out the current HEAD? – wRAR Mar 18 '13 at 18:04
  • At this moment, I would recommend doing this: 1) commit whatever uncommitted changes you have; 2) do `git branch temp` to save your current line of work as a branch -- just in case, while supposedly it just contains some commits from the remote history of "Design0.5"; 3) Check out `Design0.5` and start afresh. – kostix Mar 19 '13 at 07:03
  • @wRAR I did git checkout origin/DictDesign0.5 which I see was an error as I should have checked out the remote origin instead. – fairflow Mar 19 '13 at 10:37

2 Answers2

3

How do I get to a state where I really am tracking Design0.5 as it is remotely?

You are tracking the remote branch. That is why you get information about how outdated you local branch is. The [behind 5] tells you that your local branch is 5 commits behind the one it is tracking, i.e. the remote branch.

Tracking branches do not update itself automatically to the state of the remote branch; doing this would remove the control you have over your own, local branches.

So what is a remote-tracking branch then? A remote-tracking branch is really just like any local branch: It is a (moveable) pointer to a commit in the history of your repository. The only difference is that a remote-tracking branch in addition knows which remote branch it tracks. And this tracking is really just a “gimmick” to get information about how your local branch differs from the remote branch (the behind/ahead information) and to quickly know which remote it has to pull from or push to. Other than that, there is no additional magic.

Now, back to your situation; you are currently on a detached HEAD. It’s difficult to say why exactly you got to that sitation here. What I assume is that you started the pull --rebase, which will rewrite your local commits, and you encountered a conflict. In that case the rebasing pauses and waits for you to solve the conflict and then continue the rebasing. A git status should help to confirm that here. If you know that you don’t want to keep whatever you did on the detached HEAD, then you can simply check out a branch and get back to a normal state.

To actually update your remote-tracking branches (or any branch really) you just have to check them out and run a git merge origin/otherbranch to update it to the state of your fetched remote branch, or you just run git pull to fetch the tracked remote and get the most updated version pulled in.

poke
  • 369,085
  • 72
  • 557
  • 602
  • Hmm. No, there were no conflicts. yes, I understand now that my local branch is behind the remote (though this does not explain why the remote is reported as behind where the remote actually is...) $ git status # Not currently on any branch. # Untracked files: etc etc – fairflow Mar 18 '13 at 22:11
  • @fairflow, "the remote is reported as behind where the remote actually is" might be due to the fact you did not do `git fetch origin`, and your remote branches (those `refs/remote/origin/otherbranch` etc) did not get updated. As @Cags pointed out, `git pull` does *not* update remote branches as it explicitly operates only on the branch(es) it was told to pull. – kostix Mar 19 '13 at 07:00
  • Yes @kostix I think that's it. – fairflow Mar 19 '13 at 12:29
1

The 'commits behind' messages always used to confuse me because I'd always been taught that git pull is "the same as git fetch followed by git merge." As far as the current branch is concerned this may be true, however doing git pull doesn't actually update the local reference remotes/origin/your-branch. If you do git fetch, the references should jump back into line.

Peter O'Callaghan
  • 6,181
  • 3
  • 26
  • 27
  • Yes, thanks, that did sort out the remote references (my head is still unconnected but I think I can sort that out now). – fairflow Mar 18 '13 at 22:15