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

BUG or FEATURE? Use of '/' in branch names

From
KDKeith Derrick <keith.derrick@lge.com>
Date
May 2, 2014, 22:04 UTC
Message-ID
<AAC0CF0A2CCEC34CBE983015FD81C4F7392A504B61@AICEXMBXCL02.LGE.NET>
In-Reply-To
<5363D1B4.1000503@lge.com>
According to https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html a '/' is character to use in a branch name.
git imposes the following rules on how references are named:
1. They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence .lock.
git-flow, for example,  uses it extensively to prefix branches with 'release/', 'bugfix/', 'hotfix/' etc.
However, I just ran into the following problem
    $git init
    Initialized empty Git repository in /home/keith/play/bug2/.git/
    $touch a
    $git add a
    $git commit -m "C1"
    [master (root-commit) d569d5b] C1
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
    $git checkout -b hotfix
    Switched to a new branch 'hotfix'
    $git checkout -b hotfix/b2
    error: unable to resolve reference refs/heads/hotfix/b2: Not a directory
    fatal: Failed to lock ref for update: Not a directory
    $
The problem arises when a branch already exists with a name matching the stem of the new branch name.
As far as I can see, this comes from the use of the branch name to create a directory under .git/refs/heads with the name 'hotfix/b2' because .git/refs/heads/hotfix already exists as a plain file.
Note, however that this works
    $git init
    Initialized empty Git repository in /home/keith/play/bug3/.git/
    $touch a
    $git add a && git commit -m 'C1'
    [master (root-commit) 304052c] C1
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
    $git checkout -b hotfix/b1
    Switched to a new branch 'hotfix/b1'
    $git checkout -b hotfix/b2
    Switched to a new branch 'hotfix/b2'
    $ls .git/refs/heads/ -R
    .git/refs/heads/:
    hotfix  master
    .git/refs/heads/hotfix:
    b1  b2
    $
But, for the reverse reason, I can't now create the branch named 'hotfix'
I can see the value in grouping branches in a directory tree under refs/heads, but wouldn't it make more sense to simply escape the '/' in the branch name so that 'hotfix/b1' is stored on disk as 'hotfix\/b1'?
I found this when trying to document a branching workflow for support branches. The repositories already had branches such as 'release1', 'release2' and I wanted to add branches such as 'release1/develop', 'release2/develop', 'release1/staging', 'release2/staging' etc.
Renaming the existing published branches is not an option for us, I'm afraid.
Next: Felipe Contreras
Message 1 of 8 in “BUG or FEATURE? Use of '/' in branch names”
  1. Keith DerrickMay 2, 2014
  2. Felipe ContrerasMay 2, 2014
  3. Junio C HamanoMay 2, 2014
  4. Jonathan NiederMay 2, 2014
  5. Keith DerrickMay 2, 2014
  6. Jonathan NiederMay 2, 2014
  7. Dennis KaarsemakerMay 3, 2014
  8. Michael HaggertyMay 4, 2014

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.