10

I have a git branch that continually gets 'recreated' with an alternating letter case every time I perform a 'git pull'. Assuming the branch name is 'a' (or 'A' for all I know), one 'git pull' will produce the line:

* [new branch]      a       -> origin/a

And then the next 'git pull' will produce:

* [new branch]      A       -> origin/A

This never stops. I don't know how the branch got created (or what it is for) as someone else created it.

How do I tame this branch and make it stop doing this?

acoward
  • 240
  • 3
  • 8
  • 1
    Does this branch (or branches?) show up in the output of `git ls-remote origin`? – Cascabel May 16 '11 at 12:39
  • You appear to have hit on something. There are indeed two branches showing up in this listing. One is refs/head/a and the other is refs/head/A. I assume this means someone created the two branches with differing case without noticing, right? – acoward May 16 '11 at 15:17

3 Answers3

7

As mentioned in the comments, both refs/heads/A and refs/heads/a exist on the remote. That does mean that two distinct branches exist there. (Git itself is case sensitive, as are most non-Windows filesystems.)

If, however, you're using Windows, that would probably explain this problem. Refs are created as individual files, one per ref. Git sees both on the remote, but then when it attempts to update them locally, only one exists, so the other is always created. The internal order of the two operations must then be such that the newly created one overwrites the other, leading to the alternation.

If the refs are pointing to the same commit, then the solution is to delete one of them on the remote:

git push origin :refs/heads/A
Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • This can also happen on Mac OS X (I reproduced it), where there is also a workaround (if one of the branches can not just be deleted/renamed): use *Disk Utility* to create a disk image with a “Mac OS Extended (Case-sensitive, Journaled)” filesystem on it (**File** > **New** > **Blank Disk Image…**) and `cd` to the new volume before cloning the case-sensitive repository. – Chris Johnsen May 17 '11 at 03:46
1

It seems that origin/a and origin/A are deleted locally since you get [new branch] all the time. If someone or something is deleting these references, you will get these branches every time you fetch (or pull) from the remote. Have you tried to re clone the repository? Are you the only one having this problem?

rtn
  • 127,556
  • 20
  • 111
  • 121
  • I am not the only one having this problem. I first encountered this when someone else on the team had this problem and thought re-cloning could fix it. I'm not sure if they tried re-cloning and it went away. I will find out. Now I have the same problem. I don't believe a delete is happening locally as this occurs every time even when nothing else happens in the local repo. I can perform the 'git pull's in immediate succession and this still happens every time. – acoward May 16 '11 at 06:49
  • Do you have any git hooks firing off when you do pull? – rtn May 16 '11 at 08:03
  • I'm a git newb. I presume that since I wouldn't know how to get git hooks firing that I don't have them, right? – acoward May 16 '11 at 15:18
1

I just encountered this problem. In my case, one of the branch names was in direct descent from the other, so I deleted the older branch from the remote, as it was adding no value. Assume the branch to delete is "a", then this command will remove it from the remote (named "origin"):

git push origin :a

A couple of fetches and the problem is gone (until someone else pushes it again...)

Spencer
  • 473
  • 6
  • 13