Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git fetch: Remote keeps deleting and adding branches

Tags:

git

Everytime I fetch from all remotes, a remote from another user keeps getting branches deleted and re-added again:

Fetch with prune:

git -c diff.mnemonicprefix=false -c core.quotepath=false fetch --prune jcaseiro
From https://my.url.com/jcaseiro/project-android
 x [deleted]         (none)     -> jcaseiro/Sprint8/bugfix/SIMSwap-Master
 x [deleted]         (none)     -> jcaseiro/Sprint8/bugfix/addCheckForNullLinkFragment
 x [deleted]         (none)     -> jcaseiro/Sprint8/bugfix/fixErrorRedirectsPPEScreen
 x [deleted]         (none)     -> jcaseiro/Sprint8/bugfix/fixNullPointerExceptionDropboxInfo
 x [deleted]         (none)     -> jcaseiro/sprint7/bugfix/Fix_clickable_almost_there_screen
 x [deleted]         (none)     -> jcaseiro/sprint7/bugfix/PromoTextAlbanianString
 x [deleted]         (none)     -> jcaseiro/sprint7/bugfix/addCheckForNullLinkFragment
 x [deleted]         (none)     -> jcaseiro/sprint7/bugfix/fixPPEErrorRedirects

 * [new branch]      Sprint7/bugfix/Fix_clickable_almost_there_screen -> jcaseiro/Sprint7/bugfix/Fix_clickable_almost_there_screen
 * [new branch]      Sprint7/bugfix/LogoutNotificationProblem -> jcaseiro/Sprint7/bugfix/LogoutNotificationProblem
 * [new branch]      Sprint7/bugfix/PromoTextAlbanianString -> jcaseiro/Sprint7/bugfix/PromoTextAlbanianString
 * [new branch]      Sprint7/bugfix/addCheckForNullLinkFragment -> jcaseiro/Sprint7/bugfix/addCheckForNullLinkFragment
 * [new branch]      Sprint7/bugfix/fixPPEErrorRedirects -> jcaseiro/Sprint7/bugfix/fixPPEErrorRedirects
 * [new branch]      Sprint7/bugfix/fixWrongBehaviorBroke -> jcaseiro/Sprint7/bugfix/fixWrongBehaviorBroke
 * [new branch]      Sprint7/bugfix/fixWrongBehaviorBroke1.3 -> jcaseiro/Sprint7/bugfix/fixWrongBehaviorBroke1.3
 * [new branch]      Sprint8/Bugfix/SIMSwap-Master -> jcaseiro/Sprint8/Bugfix/SIMSwap-Master
 * [new branch]      Sprint8/Bugfix/addCheckForNullLinkFragment -> jcaseiro/Sprint8/Bugfix/addCheckForNullLinkFragment
 * [new branch]      Sprint8/Bugfix/fixErrorRedirectsPPEScreen -> jcaseiro/Sprint8/Bugfix/fixErrorRedirectsPPEScreen
 * [new branch]      Sprint8/Bugfix/fixNullPointerExceptionDropboxInfo -> jcaseiro/Sprint8/Bugfix/fixNullPointerExceptionDropboxInfo

Even if I delete the remote, and added it again, it keeps on happening.

It only happens with this specific remote, but I believe there is something wrong with my local git, because the other developers of this project don't experience such thing**.

Fetch without prune (everytime):

 git -c diff.mnemonicprefix=false -c core.quotepath=false fetch jcaseiro
From https://my.url.com/jcaseiro/project-android

 * [new branch]      Sprint7/bugfix/Fix_clickable_almost_there_screen -> jcaseiro/Sprint7/bugfix/Fix_clickable_almost_there_screen
 * [new branch]      Sprint7/bugfix/LogoutNotificationProblem -> jcaseiro/Sprint7/bugfix/LogoutNotificationProblem
 * [new branch]      Sprint7/bugfix/PromoTextAlbanianString -> jcaseiro/Sprint7/bugfix/PromoTextAlbanianString
 * [new branch]      Sprint7/bugfix/addCheckForNullLinkFragment -> jcaseiro/Sprint7/bugfix/addCheckForNullLinkFragment
 * [new branch]      Sprint7/bugfix/fixPPEErrorRedirects -> jcaseiro/Sprint7/bugfix/fixPPEErrorRedirects
 * [new branch]      Sprint7/bugfix/fixWrongBehaviorBroke -> jcaseiro/Sprint7/bugfix/fixWrongBehaviorCloudBroker
 * [new branch]      Sprint7/bugfix/fixWrongBehaviorBroke1.3 -> jcaseiro/Sprint7/bugfix/fixWrongBehaviorCloudBroker1.3
 * [new branch]      Sprint8/Bugfix/SIMSwap-Master -> jcaseiro/Sprint8/Bugfix/SIMSwap-Master
 * [new branch]      Sprint8/Bugfix/addCheckForNullLinkFragment -> jcaseiro/Sprint8/Bugfix/addCheckForNullLinkFragment
 * [new branch]      Sprint8/Bugfix/fixErrorRedirectsPPEScreen -> jcaseiro/Sprint8/Bugfix/fixErrorRedirectsPPEScreen
 * [new branch]      Sprint8/Bugfix/fixNullPointerExceptionDropboxInfo -> jcaseiro/Sprint8/Bugfix/fixNullPointerExceptionDropboxInfo

For informational purposes, I'm using SourceTree, but doing it via command line has the exact same effect.

I've googled a lot, but haven't find an answer for this...

like image 425
neteinstein Avatar asked Oct 31 '22 19:10

neteinstein


1 Answers

If you are using git on Windows, you are going to run into problems when:

  • there are multiple branches that are only distinguished by the case, or
  • a branch is renamed to a different case.

Take a look under your repo's .git/refs/remotes/ to figure out what is going on. Compare this against git ls-remote. It is best not to touch those .git files directly and instead manipulate them using git commands so you don't corrupt your local repository.

If the branch has been renamed to a different case, then you need to clean up your git refs, e.g.

git update-ref -d Sprint8/Bugfix/SIMSwap-Master

You should repeat that for every branch being deleted and re-created on every fetch. You might need to exhaustively git update-ref -d an entire folder of refs if the folder's case changed. (I just did this for about 200 branches -- I ran a vim macro on the fetch output to generate the 200 commands -- as far as I know there isn't an option to recursively git update-ref -d a folder of refs.) The next fetch will get any renamed branches one last time, but subsequent fetches will no longer get that branch.

If the branch wasn't just renamed, but actually exists multiple times only differing by case, you should ask the developer who created the branches to delete the extra branches so that there are no branches that only differ by case. You are going to keep seeing the same branch every fetch until there are no longer duplicate branches that only differ by case.

On Windows git bash, you might try the following command to list all the branches that only differ by case:

git ls-remote --refs origin | tr '[A-Z]' '[a-z]' | sort | uniq -c | grep -v $' 1\t'
like image 80
JDiMatteo Avatar answered Nov 15 '22 04:11

JDiMatteo