1

In a possibly misguided attempt at organizing branch names, I attempted to make two branches where one was a "subpath" of the other — say, "foo" and "foo/bar" — and git refused to make the second one:

error: 'refs/heads/foo' exists; cannot create 'refs/heads/foo/bar'

Considering how the .git/refs/heads is organized, at least on my system, this makes sense — a branch is a file in heads, but slashes in branch names create directories, and a single entry can't be a file and a directory at the same time.

However, I can't find this limitation mentioned in the documentation. Is it a formal restriction, or is it just an implementation limit that everyone learns to avoid?

Chris N
  • 905
  • 5
  • 10
  • https://stackoverflow.com/search?q=%5Bgit%5D+error%3A+%27refs%2Fheads%2F%27+exists%3B+cannot+create+%27refs%2Fheads%2F%27 – phd Sep 24 '19 at 22:25
  • 1
    does this answer your question: https://stackoverflow.com/a/2527452/4880924 – BenKoshy Sep 24 '19 at 22:25
  • 1
    When you put a slash in a branch name git creates a folder. So foo/bar would create a folder foo with a file bar inside it. However it seems git won’t let you do this if a branch name (a file with that name) already exists. – evolutionxbox Sep 24 '19 at 22:29
  • I agree that this is essentially a duplicate of https://stackoverflow.com/questions/22630404/git-push-refs-heads-my-subbranch-exists-cannot-create, but @chris-yungmann's answer directly answers my question. – Chris N Sep 24 '19 at 23:41

1 Answers1

1

I believe it is an undocumented implementation limitation of the files backend and packed ref store backend. In theory the git codebase can be extended with additional backends that do not have the same limitation. See this mailing list thread for some discussion.

Chris Yungmann
  • 1,079
  • 6
  • 14