git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Branch names with slashes

From
NKNeal Kreitzinger <nkreitzinger@gmail.com>
Date
Dec 15, 2011, 20:40 UTC
Message-ID
<4EEA5B55.1040405@gmail.com>
In-Reply-To
<CAGcUY13TOodu1BO3DCoNnVvNZ9QkWAbD-RmyqQX6P1q6tcO+yg@mail.gmail.com>
On 12/14/2011 4:17 AM, Leonardo Kim wrote:
Show 14 quoted lines
> Branch names can contain slashes, so we can use 'development/foo' as
> a branch name. If I choose 'development' as a branch name, it doesn't
> work. There is a directory named development at '.git/refs/heads'
> directory. So we cannot create a file named development for
> 'refs/heads/development'.
>
> An error message may occurs like below. Unfortunately, It is not of
> help to me. 'error: 'refs/heads/development/foo' exists; cannot
> create 'refs/heads/development'.
>
> I think that dealing with a file system and an error message above is
> not sufficient for a novice like me. I hope that it should be
> improved.
>

FYI, We also use slashes in our branchnames to leverage some of the benefits of a path-like namespace like pattern matching and the logical expression of hierarchies using descriptive compound names. (We use git 1.7.1 on linux.) Here's something to keep in mind: You have to plan (think ahead) for your naming conventions so that the namespaces will maintain uniqueness at a peer level over time that cannot be confused as subdirs under .git/refs/heads. For example:

branchnames: /mysystem/generic /mysystem/generic/project1

will not work because /mysystem/generic appears to be a parent dir to /mysystem/generic/project1 under .git/refs/heads. The solution is:

/mysystem/generic/base /mysystem/generic/project1

these branches can coexist because they are unique without one appearing to be a parent dir of the other. IOW, their namespaces are peers in their entirety. To carry the example a little further,

/mysystem/generic/project1/part2 will not work because once again it appears to be a subdir of an existing branchname (ref). However, /mysystem/generic/project1-part2 will work.

I think the reason for this is that if you look at .git/refs/heads you will see that these slash delimited branch names are actually stored as subdirs in the filesystem sense. Therefore, git will get confused and error out as it tries to find branchnames that are not entirely unique by their full path namespace under .git/refs/heads because a branch namespace that is a prefix (in the filesystem sense) of another branch name would occupy the same path under .git/refs/heads without being distinguishable as unique, and vice versa.

Hope this helps. (Maybe someone else will find a clearer way to explain this.)

v/r, neal

Previous: Michael HaggertyNext: Michael Haggerty
Message 3 of 6 in “Branch names with slashes”
  1. Leonardo KimDec 14, 2011
  2. Michael HaggertyDec 14, 2011
  3. Neal KreitzingerDec 15, 2011
  4. Michael HaggertyDec 15, 2011
  5. Junio C HamanoDec 16, 2011
  6. Johannes SixtDec 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.