19

I am having a constant issue with one of my git repos. I keep getting the following error:

    fatal: Unable to create 'v:/path/to/files/.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.

I have tried: rm -f ./.git/index.lock as per another thread on stackoverflow but I get this error each time: rm: cannot unlink `./.git/index.lock': Permission denied

When I close down aptana (I am using git in the terminal) I cannot delete the file still.

Any ideas how to get around this?

Another thing to note is this git repo is very slow when I do occasionally get to commit within it (it allows me every 10 tries or so)

Thanks

4
  • It works for me stackoverflow.com/questions/17916339/… Commented Jul 29, 2013 at 5:41
  • Do you have root or superuser access to the system you are using? In other words, do you own the computer or are you on a public computer, such as in a campus lab? Commented Oct 8, 2013 at 17:59
  • these commands are for unix and osx systems. you can go to the index.lock file in the explorer and delete it. if you dont see .git folder. you need to set show hidden files in your file folder manager first Commented Dec 5, 2014 at 8:21
  • Try using "rm .git/index.lock"or refer this robots.thoughtbot.com/how-to-fix-rm-f-git-index Commented Nov 30, 2016 at 10:21

7 Answers 7

32

Sudo the command:

sudo rm -f ./.git/index.lock

Both errors suggest index.lock is owned by another user. Run the rm as a superuser, then try your commands again. You might also consider setting core.sharedRepository to true if that is, in fact, the case with your repo:

core.sharedRepository

When group (or true), the repository is made shareable between several users in a group (making sure all the files and objects are group-writable).

When all (or world or everybody), the repository will be readable by all users, additionally to being group-shareable. When umask (or false), git will use permissions reported by umask(2). When 0xxx, where 0xxx is an octal number, files in the repository will have this mode value. 0xxx will override user's umask value (whereas the other options will only override requested parts of the user's umask value). Examples: 0660 will make the repo read/write-able for the owner and group, but inaccessible to others (equivalent to group unless umask is e.g. 0022). 0640 is a repository that is group-readable but not group-writable.

See git-init(1).

False by default.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, I tried to sudo, I got this: sh: sudo: command not found. Also I don't know how to log in as a super user, I only just started using git this week.
I am still having huge issues with this, every day when I try I get the index.lock error. I am still getting the sh: sudo: command not found and cannot manually delete the file, always permission denied. Any ideas? Thanks!
@sluggerdog What operating system are you on? Also, how are you running the git commands?
I'm using windows 7, 64bit. Thanks
This is a permissions problem; specifically, you're running the git command with inconsistently permissioned users. I know how to fix this on POSIX, not on Windows, I'm afraid, but it can't be difficult.
4

The issue ended up being Aptana, everytime I ran this it would cause this error when I tried to commit in git.

I stopped using aptana studio and I don't have this issue anymore.

1 Comment

I guess, several editors cause it. For me it could be visual studio code.
1

You also get this error if you are using Aptanta Git and other git clients, like f.e. TortoiseGit. So it is likely that this other Git software locked your Git, making it unavailable for Aptana.

Comments

1

Do this:

rm index.lock

followed by

git reset

2 Comments

If OP can't delete the file, how is rm going to help? If you're simply suggesting that OP not use the -f flag, please explain why you think that's the solution.
thanks, I've got stuck in the same problem for minutes and this simples commands just saved me
1

Be careful with

rm -f .git/index.lock
git reset

Doing a git reset will delete any uncommitted changes that you've made.

Deleting your index.lock will mean that git will not be able to track any local changes.

One alternative for restoring your index.lock could be to git stash your last commit (if it's not yet pushed), and then do a git stash pop to add it back in.

So:

rm -f .git/index.lock
git stash
git stash pop

This will create a new index.lock without doing a git reset.

If you had previously git added some files without committing, you will need to git add those files again.

It's a bit of a hack. Comments?

Comments

0

This may be an old reply but I'm hoping this is more useful on next who need this solution.

On linux/unix/gitbash/cygwin, try

rm -f .git/index.lock

On Windows Command Prompt, try:

del .git\index.lock

Hope that helps, I found this solution here: fatal: Unable to create 'project_path/.git/index.lock': File exists.

5 Comments

rm won't work since they don't have permissions - as it's owned by someone else - unless you sudo the command. "I have tried: rm -f ./.git/index.lock as per another thread on stackoverflow but I get this error each time: rm: cannot unlink `./.git/index.lock': Permission denied"
sudo is needed only project is own by some other user otherwise won't. So it's not mandatory part.
It is owned by someone else, specifically used by Aptana.
When project having 777 permission it doesn't matter used by aptana or any other ide .
..and where does it say OP permissions are 777? Your answer gives no real help to the OP; it's re-iterating what they've tried.
0

In git version 2.11.0, .git folder may not include the index.lock file. I figured out in the .git/refs/heads/ folder contains a .lock file and removing it using rm command works.

Also be sure to kill the process that might be using git repo using ps -aef | grep git and kill -9.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.