{"thread":{"id":"62748","subject":"bug: Removing branch and creating branch-directory with same name breaks","startedAt":"2025-01-06T19:10:25Z","lastAt":"2025-01-06T22:25:47Z","messageCount":2,"participants":["Matthias Braun","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"510005","messageId":"25913110-E42E-4028-B39D-44045623FDC4@braunis.de","threadId":"62748","inReplyTo":null,"subject":"bug: Removing branch and creating branch-directory with same name breaks","fromName":"Matthias Braun","fromEmail":"matze@braunis.de","sentAt":"2025-01-06T19:07:01Z","receivedAt":"2025-01-06T19:10:25Z","isPatch":false,"sender":{"key":"matze@braunis.de","avatar":null},"body":"(Note that I also tried this with latest git-2.47.1 after creating the repro script and it still fails there).\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n- Removed remote branch. Created new directory (for branch names)\n  with same name directory name as the previously used branch name.\n  After that `git fetch` fails.\n\nReproduction script for your convenience:\n```\n#!/bin/bash\n\nmkdir -p repro\ngit init repro/remote.git\ngit clone repro/remote.git repro/cloned\npushd repro/cloned\necho \"hello\" > hello.txt\ngit add hello.txt\ngit commit -m \"test commit\"\ngit branch mystuff\ngit push origin mystuff\npopd\n\ngit clone repro/remote.git repro/clone2\n\npushd repro/cloned\ngit branch -D mystuff\ngit push -d origin mystuff\ngit branch mystuff/branch_in_subdir\ngit push origin mystuff/branch_in_subdir\npopd\n\npushd repro/clone2\ngit fetch    #  This fails as branch turned into directory\npopd\n```\n\nWhat did you expect to happen? (Expected behavior)\n\n`git fetch` should work...\n\nWhat happened instead? (Actual behavior)\n\n`git fetch origin`\nerror: cannot lock ref 'refs/remotes/origin/mystuff/branch_in_subdir': 'refs/remotes/origin/mystuff' exists; cannot create 'refs/remotes/origin/mystuff/branch_in_subdir'\n\nWhat's different between what you expected and what actually happened?\n\nAnything else you want to add:\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.43.5\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.19.0-0_fbk12_hardened_11583_g0bef9520ca2b #1 SMP Fri Feb 2 17:56:12 PST 2024 x86_64\ncompiler info: gnuc: 11.4\nlibc info: glibc: 2.34\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show"},{"id":"510023","messageId":"Z3xYY5A7BblBiYmG@tapette.crustytoothpaste.net","threadId":"62748","inReplyTo":"25913110-E42E-4028-B39D-44045623FDC4@braunis.de","subject":"Re: bug: Removing branch and creating branch-directory with same name breaks","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-01-06T22:25:39Z","receivedAt":"2025-01-06T22:25:47Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-01-06 at 19:07:01, Matthias Braun wrote:\n> (Note that I also tried this with latest git-2.47.1 after creating the repro script and it still fails there).\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> - Removed remote branch. Created new directory (for branch names)\n>   with same name directory name as the previously used branch name.\n>   After that `git fetch` fails.\n> \n> Reproduction script for your convenience:\n\nThanks for the reproduction steps.  This is expected, and I'll explain\nmore below.\n\n> ```\n> #!/bin/bash\n> \n> mkdir -p repro\n> git init repro/remote.git\n> git clone repro/remote.git repro/cloned\n> pushd repro/cloned\n> echo \"hello\" > hello.txt\n> git add hello.txt\n> git commit -m \"test commit\"\n> git branch mystuff\n> git push origin mystuff\n> popd\n> \n> git clone repro/remote.git repro/clone2\n> \n> pushd repro/cloned\n> git branch -D mystuff\n> git push -d origin mystuff\n> git branch mystuff/branch_in_subdir\n> git push origin mystuff/branch_in_subdir\n> popd\n> \n> pushd repro/clone2\n> git fetch    #  This fails as branch turned into directory\n> popd\n> ```\n> \n> What did you expect to happen? (Expected behavior)\n> \n> `git fetch` should work...\n> \n> What happened instead? (Actual behavior)\n> \n> `git fetch origin`\n> error: cannot lock ref 'refs/remotes/origin/mystuff/branch_in_subdir': 'refs/remotes/origin/mystuff' exists; cannot create 'refs/remotes/origin/mystuff/branch_in_subdir'\n\ngit fetch does not by default delete remote tracking branches which no\nlonger exist on the remote.  That's because sometimes you want to keep\nthose around even though upstream does not.[0]\n\nIn this case, or if you just don't want to keep them around, you can use\n`git fetch --prune origin` to prune those old branches when fetching, or\n`git remote prune origin` to just prune and not fetch (and, of course,\nthese work with any remote, not just `origin`).  The `git fetch` manpage\nmentions the `fetch.prune` and `remote.<name>.prune` options for you to\ncontrol this automatically as you see fit.\n\n[0] At a previous employer, large projects were squashed-and-merged, and\nI found keeping around the original history—and thus the original\nbranches—was invaluable to understanding why a change was made or who I\nshould talk to about a particular change if I had questions.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"}]}