0

When I create a branch on existed sub-branch I get error like this:

fatal: cannot lock ref 'refs/heads/dev/mine/test': 'refs/heads/dev/mine' exists; cannot create 'refs/heads/dev/mine/test'

If there was no sub branch "dev/mine" then I can create "dev/mine/test".

If "dev/mine" branch already exists, how can I create "dev/mine/test" branch?

DeathPro
  • 98
  • 6
  • https://stackoverflow.com/search?q=%5Bgit%5D+fatal%3A+cannot+lock+ref+exists%3B+cannot+create – phd Oct 20 '22 at 14:44

1 Answers1

2

You can't.

Pretend that branch names are filenames; a / separated component can either be a "directory" or a "file". If you've created a branch named dev/mine, then mine is a "file" -- that is, it cannot contain any child entries.

So you can create dev/mine/feature1, dev/mine/test, etc., as long as you don't create dev/mine first.

You can always rename a branch if you decide you've picked the wrong naming strategy:

git branch -m dev/mine dev/mine/<whatever>
larsks
  • 277,717
  • 41
  • 399
  • 399
  • The "pretend" part becomes quite real when you look at `.git/refs/heads`, where the branch names are represented as an actual directory/file tree. – Benjamin W. Oct 20 '22 at 14:34