The issue
This sounds like a GitExtensions bug, to which I couldn't find specific info. I believe the issue arises when you have a bare repository with more than 1 branch. If you then push, you'll get a warning that if you choose to ignore you'll find the mess up branches. Or depending on how you push it, not even the warning comes up and it's doom everywhere!
Let's say we have 2 local branches called master
and another
. And the default origin
set for pushing. After a regular push we'd also find origin/master
and origin/another
, that's all.
But after the doomed push, we'll find duplicated origin/master
and origin/another
plus origin/refs/heads/master
and that's also duplicated. For every extra branch. And it's not like we're pushing all branches or something, nor are we using Multiple Branches feature.
In fact, after this happening, we can't even simply push
without an error! (yes, using windows of course)
Pushing to \\\server\git\repo error: dst refspec refs/heads/another matches more than one. error: failed to push some refs to '\\\server\git\repo'
The problem becomes way evident when listing branches with git branch -r
.
To fix it
We need to do something like this:
- Manually remove the
refs/heads
folder inorigin
. Some times it works just usinggit push origin :<branchName>
, others we need to go more robust and directly into the folder. This is the hard step and main problem happens when those don't work... git fetch -p
, for bringing origin changes to local.- Eventually going through all clients and using
git remote update
. If needed, removing the same branches, one by one or by any means, like robustly and directly into the folder again. There's yet another problem in this steps, sometimes, which I can't diagnose yet.
The frequency
To us, this is a stated fact. Even though I haven't done many experiments to see what exactly causes it, it does happen in any of 5 machines using this repo, all configured the same way except for the bare
.
And every single time it happens I have to run and find out on how to fix it. This time I decided to document it, since I could never find anything on the web specific enough.
Why
The question here is: why this happens, and how to prevent it? Is it even GitExtensions fault only? That sure happens, in our side, only with this specific scenario, in GitExtensions.