V
V
Vann Damm2020-04-20 16:15:40
git
Vann Damm, 2020-04-20 16:15:40

Preventing me from creating a new git branch?

I created a new branch, made a commit in it, switched to the main (master) and I can’t create a new branch from it, such an error crashes:
5e9da0696bf91458604917.png
What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-04-21
@effect_tw

Because initially (and even now) links (i.e. branches, tags, etc.) are stored as files in the file system (if you do not consider compression). Look, for example.
ls .git/refs/heads
Accordingly, if you already have a frontEnd/bodyStart branch, then there is a .git/refs/heads/frontEnd folder and obviously you cannot create a file with the same name.
PS Specifically, you may not have anything in the .git/refs/heads folder , because git has a storage optimization system. But for compatibility, the restriction on creating such branches still remains for compatibility.

example

$ ls .git/refs/heads/
master

$ git branch test/head
$ tree .git/refs/heads/
.git/refs/heads/
├── master
└── test
    └── head

$ git branch test
fatal: cannot lock ref 'refs/heads/test': 'refs/heads/test/head' exists; cannot create 'refs/heads/test'

$ git branch -d test/head
Deleted branch test/head (was 58084de).
$ git branch test
$ tree .git/refs/heads/
.git/refs/heads/
├── master
└── test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question