Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to create a branch on the current branch on my Ubuntu guest.
Unfortunately I keep getting this error:
git checkout -b origin/feature/IF-53-change-validation-window/Tommaso
fatal: cannot lock ref 'refs/heads/origin/feature/IF-53-change-validation-window/Tommaso':
'refs/heads/origin/branch' exists;
cannot create 'refs/heads/origin/branch/Tommaso'
I tried git gc --prune=now as suggested here link, but keep getting the same error.
–
–
It looks like the problem here was a branch X existed locally, and you tried to create a new branch X/Y. This won't work, because there will be a file at .git/refs/heads/X, so git can't also create the folder X.
However, it's worth adding that including "origin" in your branch name points to some confusion - origin is usually the name of the remote repository. If you run git branch I expect you will see local branches with origin in the name.
The format git checkout X is shorthand for:
look for a local branch X and check that out if it exists
otherwise look for a remote branch X and check that out locally (git checkout -b X origin/X)
To fix your current state, you can likely do this (see here):
git update-ref -d refs/heads/origin/branch
–
–
–
–
–
–
–
I was looking for answer here, but actually my problem was simpler, yet unresolvable.
fresh clone of repo
git checkout foo/bar
git checkout -b foo/bar/baz
got similiar error message.
As described here, you cannot use foo/bar both as a branch and directory. I had to change proposed naming convention.
–
–
–
–
This happend to me, too.
The reason was that I tried to create a branch with a too deep directory.
The deepest directory to successfully create was:
origin/titleA/titleB/nameOfTheNewBranch
and I first tried to create it one step deeper in
origin/titleA/titleB/titleC/nameOfTheNewBranch
which seemed to be too deep 'cause it does not work.
–
refs/heads
The HEAD file is usually a symbolic reference to the current branch. The so-called symbolic reference means that it is a pointer to another reference.
every branch you make(such as s/a/b/c/d) will create a path in refs/heads.
A file named 'd' which save a SHA-1 values would be touch in the path: refs/heads/s/a/b/c/d
so the problem is, you made a branch named "origin/branch" already,
so you can't make any branch named "origin/branch/xxxx" any more, why? because if u do so, git have to create a path named "origin/branch/xxxx" which would create a folder named 'branch', but u have a file named 'branch' already right? SO.
I just go a similar problem and the reason is, because of deleting the branch on the repo I couldn't access it to local so , what I do is delete the local branch and pull the new branch from the repo then create the feature branch and it did work
if you delete the branch in the repo it is still available in local
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.