Skip to content

Instantly share code, notes, and snippets.

@ayozebarrera
Created September 22, 2017 11:14
Show Gist options
  • Save ayozebarrera/a2a03569b83f745751b61480bb0c1a32 to your computer and use it in GitHub Desktop.
Save ayozebarrera/a2a03569b83f745751b61480bb0c1a32 to your computer and use it in GitHub Desktop.
How to fix `rm -f .git/index`

How to fix rm -f .git/index

Ever gotten this message?

fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.

If no other git process is currently running, this probably means a git process crashed in this repository earlier. Make sure no other git process is running and remove the file manually to continue.

The way to fix this:

rm .git/index.lock

If you instead do this (note the lack of “.lock” at the end):
rm .git/index
then your git repo will behave in very weird ways. For instance, git status won’t work, and other things break in odd ways.

Here’s the fix:
git read-tree --reset HEAD

You’ll lose unstaged changes, but you’ll have your repo back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment