Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git fatal: cannot lock ref

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.

like image 875
Tommaso Guerrini Avatar asked Jul 17 '17 09:07

Tommaso Guerrini


People also ask

Can t lock ref git?

"error: cannot lock ref" simply means information in /refs are corrupted and Git cannot continue to create index.

How do I fix broken references in git?

Solution. Unsure the root cause of the "reference broken". To fix it, delete this file . git/refs/remotes/origin/master , and git fetch to retrieve it back.

What is prune in git?

The git prune command is an internal housekeeping utility that cleans up unreachable or "orphaned" Git objects. Unreachable objects are those that are inaccessible by any refs. Any commit that cannot be accessed through a branch or tag is considered unreachable. git prune is generally not executed directly.


1 Answers

You shouldn't be checking out branches that begin with "origin" or any other existing branch name.

Assuming that branch exists on origin, you should do the following:

git checkout feature/IF-53-change-validation-window/Tommaso 

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)."

If you are creating a new local branch, you will often do the following:

git checkout -b new-branch 

This will create a new branch pointing at the same commit as you had checked out previously.

To fix your current state, you can likely do this (see here):

git update-ref -d refs/heads/origin/branch 
like image 86
cmbuckley Avatar answered Sep 23 '22 14:09

cmbuckley