-3

For example, I have a branch named /feature and I wanted to create a new feature branch under it, like feature/MyTask-01.

I tried using command git branch feature/MyTask-01 but it always gives me this error:

$ git branch feature/My-Task-01
fatal: cannot lock ref 'refs/heads/feature/My-Task-01`: 'refs/heads/feature' exists; cannot create 'refs/heads/feature/My-Task-01'
1

1 Answer 1

1

Git stores branches in refs/heads/.

  1. Creating a branch branch feature stores a file: refs/heads/feature.
  2. Creating a branch feature/abc attempts to store a file refs/heads/feature/abc.

Both cannot be possible, since refs/heads/feature would need to be a file and a folder at the same time.

To resolve this, either

  • delete the feature branch and stick to using feature/x, or
  • call your second branch something which doesn't attempt to create the feature/ folder, such as feature_x.
Sign up to request clarification or add additional context in comments.

2 Comments

Note that sometimes, Git stores branches in a flat-file, .git/packed-refs. When Git is doing that, this restriction on names would not be necessary. Git enforces it anyway, so that when Git stores the branches in separate files, things don't suddenly stop working.
@grg Sorry for late reply, yeah this is what I am looking for. The /feature is a folder (submodule) when I saw it in the sourcetree. Thanks a lot man.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.