gitcase-insensitivegit-fetchremote-branch

Git fetch a branch once with a normal name, and once with capital letter


I'm fetching for remote branches and stuck in some sort of a loop.

I fetch once and get:

$ git fetch
* [new branch]      minorRelease/something-> origin/minorRelease/something

And then I fetch again and get:

$ git fetch
* [new branch]      minorRelease/Something-> origin/minorRelease/Something

Same branch but with a capital S.

I tried to delete the file from the following folder .git/refs/remotes/origin/minorRelease, but when fetching again, I get both and return to the loop above:

$ git fetch
* [new branch]      minorRelease/Something-> origin/minorRelease/Something
* [new branch]      minorRelease/something-> origin/minorRelease/something

Solution

  • @torek is right that it's caused by the difference of Linux and Windows. Linux is case-sensitive, while Windows is not. You can use ls-remote to show the branches in the server.

    git ls-remote --heads origin
    

    And I think in your case, the output should include the two branches with only the case of S different.

    ref/heads/minorRelease/Something
    ref/heads/minorRelease/something
    

    You can delete the remote branch if you find one of them is actually duplicated. And then do fetch again. It should be fine now.

    git push origin :minorRelease/Something
    git fetch