Bob Dylan
Bob Dylan

Reputation: 1833

Git branch naming to show parent branch

Suppose I have two main branches: master and dev. All of my development efforts are branched off of dev then merged back into dev, then eventually into releases then merged into master. I would like to name dev sub-branches with a dev/ prefix to show what they were branched from, so perhaps these are some branches:

But I cannot do this, instead getting the error:

error: unable to create directory for .git/refs/heads/dev/new-feature
fatal: Failed to lock ref for update: No such file or directory

Presumably this is because dev is an actual branch. Is there a way to make this work, or is there a better way to show this in the branch name? Thanks,

Upvotes: 3

Views: 293

Answers (2)

Joseph K. Strauss
Joseph K. Strauss

Reputation: 4903

What you are asking for unfortunately cannot work because Git refs are stored in a directory structure (unless you use pack-refs to store the refs in a single file), and the reflogs are always stored in a directory structure.

This being the case, you cannot have a file name that is the same as a directory.

Since Git sometimes allows for partial branch names based on /, e.g., the --branches= option of git log, it is NOT optimal to separate based on underscore.

Therefore, as a workaround for your situation I would suggest having a dev/main branch instead of just plain dev.

Upvotes: 2

Philippe
Philippe

Reputation: 31147

Open the '.git' folder and go to the folder 'refs/heads'. Here, you should find the file 'dev' which correspond to the branch with the same name. When you try to create a branch 'dev/new-feature', git try to create the 'dev' folder to create the 'new-feature' file inside. It can't create the folder because a file have already the same name.

So,you will understand that it's impossible :-(

Upvotes: 0

Related Questions