skip to content
blog.metters.dev

TIL about git branch name conflicts with directories

/ 2 min read

I am used to apply some structure to my branch names. Except for main/master and my test branch, branches have a short lifecycle, because I delete them after being merged. For this site I would create a branch post/title-of-the-article or at work I would include a ticket number, like so: feature/ISSUE-1337/Short-description-of-the-feature.

In both cases the first term reflects the kind of change or the reason for this branch to exist at all. Common terms I use are post, feature, bugfix/fix, ti (technical improvement).

Some developers don’t like to use the / character and prefer to use a - instead, which is totally fine, but I do it the other way round. The main difference is that a / structures the branches in directories, while a - puts all branches next to each other within the same directory.

I stumbled across this problem when I was testing something and created a test branch test/some-description. The branch could not be created, because a branch named test already exists.

Try it for yourself. Executing the second command will lead to an error

Terminal window
git co -b test
git co -b test/some-description
fatal: cannot lock ref 'refs/heads/test/some-description': 'refs/heads/test' exists; cannot create 'refs/heads/test/some-description'

Comments in Stackoverflow