0

I noticed that, for some reason, some of my git branches are prefixed with "remotes/origin":

BZ9
 * master   
 remotes/origin/BZ8   
 remotes/origin/BZ9   
 remotes/origin/HEAD -> origin/master   
 remotes/origin/junit1   
 remotes/origin/master

What is the difference between, for example, the "remotes/origin/BZ9" branch and the BZ9 branch? Clearly, they both originate from the same conceptual branch, but git is considering them to be distinct.

Charles
  • 50,943
  • 13
  • 104
  • 142
jayunit100
  • 17,388
  • 22
  • 92
  • 167

1 Answers1

0

In your listing, "BZ9" and "master" are both local branches that you can move update and delete freely. When you are on one of these branches and do a commit, the branch updates to point to your latest commit.

The remotes/origin prefixed names which show up when you type git branch -a however are just like branches but you can think of them as "read-only". These branches you don't directly control, they are automatically set when you fetch, and they won't change until you fetch (or pull) again.

That's because unlike your local branches which track your local development, the remotes/origin branches track remote development on the server where you pull from ("origin").

For example, the "remotes/origin/junit1" is saying: "the last time git fetched from the remote origin repo, there was a branch there called junit1 that was pointing to this commit hash".

You can checkout that remote branch just like any other, but when you commit to this branch, the branch pointer doesn't update, because it's not intended to track your local progress, it's intended to track the remote repo's progress.

Your local progress is tracked by your local branches, which you create, update, delete freely as needed.

Likewise, if someone else clones from your repo, then when they fetch from you they would have two remote branches from you: "remotes/origin/BZ9" and "remotes/origin/master". In other words, your local branches become remote/origin branches for someone downstream from you.

So that's all your remote/origin branches are too, they're read-only copies of your upstream repo's local branches.

Magnus
  • 10,736
  • 5
  • 44
  • 57