-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'
grg
  • 3,915
  • 3
  • 27
  • 38
Israel Ocbina
  • 411
  • 6
  • 10
  • Does this answer your question? [Create a branch in Git from another branch](https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch) – Zig Razor Feb 15 '20 at 18:29

1 Answers1

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.
grg
  • 3,915
  • 3
  • 27
  • 38
  • 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. – torek Feb 15 '20 at 19:42
  • @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. – Israel Ocbina Feb 24 '20 at 13:56