4

I have a git branch "hotfix/foo" that exists on the remote repository. Now I have created a local one with the name "hotfix/foo/bar". It will be created locally without problems. I have only the remote ref of the first branch (not pulled the "hotfix/foo" branch) on my local machine.

I cannot push the new branch "hotfix/foo/bar" to remote. Only when I delete the "hotfix/foo" on the remote, I can now push.

I am using Git for Windows, version 2.51.2.windows.1. I tried both, running it via the CMD and from VisualStudio 2026. The remote repository is stored on Azure DevOps.

Is that normal behaviour? Are there any docs pointing to this naming restriction? It happened to me twice with different synonyms for foo and bar.

This question has the same answer as this question, because the fundamentals of git cause the issues. The only difference is, that my symptoms were different.

4
  • 1
    Definitely how Git works (I've seen the same thing, in a Linux environment). It's similar to file names (and might even involve file names in the .git directory) - you can't have a directory with the same name as a (leaf) file. Commented Nov 6 at 15:43
  • 1
    stackoverflow.com/questions/2527355/… Found in stackoverflow.com/search?q=%5Bgit%5D+branch+slash Commented Nov 6 at 18:15
  • With my knowledge and words I could not find the question you refer to. Also the issue on that question is, that the branch could not be created locally. But in my case I could. How would you suggest I edit my question in the regard, that the answer of the other one is pointing in the same direction? Commented Nov 7 at 12:25
  • “Also the issue on that question is, that the branch could not be created locally. But in my case I could.”—The root cause is the same. Remote or local refs are immaterial. Commented Nov 7 at 14:00

1 Answer 1

7

The branch names are actual paths under .git/refs/ representing actual folders and files. A folder foo cannot coexist with a file foo.

Creating a branch hotfix/foo/bar creates a file .git/refs/heads/hotfix/foo/bar (which stores the commit ID of that branch). This means .git/refs/heads/hotfix/foo is now a folder, and therefore cannot be a file at the same time.

Sign up to request clarification or add additional context in comments.

3 Comments

You can prove this to yourself just by looking inside the invisible .git directory (in the refs directory).
The next Git version might finally solve this with the switch from file-based refs to the "reftable" system. But it will take another decade or two for Git servers to migrate to the new format.
Nice to know, grawity. Unfortunately you are correct. Git updates for git servers will take a long time as long as there is not something very bad on the existing version. As always

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.