Git rename from index.lock to index failed
Solution 1
Looks like the following process had a lock on the .git\index
file:
ssh-agent.exe
C:\Users\Tom\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7\bin\ssh-agent.exe
I killed the process and ran git reset HEAD
and looks like I'm back to normal now.
Solution 2
In my case, this was caused by using the same Git repo from both admin and non-admin command prompts. When last git pull
was from admin cmd, the index
was created by it, and then non-admin cmd had insufficient permissions to modify it.
My solution was re-creating the index
(while keeping the worktree intact):
del .git\index
del .git\index.lock
git reset --mixed head
Solution 3
In my case I had to close the VS code which I opened with code .
from a WSL Ubuntu terminal.
Solution 4
It can be a real issue, try to run your Terminal as Administrator instead of user. Worked for me
Solution 5
I was seeing this Rename from '.git/index.lock'...
message when attempting to execute
git checkout -b my-branch
The fix for me was to run the command line as admin
.
Specifically I was using the excellent cmder application as a non-admin, which resulted in the rename message appearing. By running cmder as an admin, then performing the checkout again, it worked fine.
Tom Hunter
SQL Server / C# developer, currently living and working in New York.
Updated on January 05, 2022Comments
-
Tom Hunter over 2 years
Using the GitHub Windows client I did a sync to pull remote changes to my local machine, but before finishing the sync, I ran out of disk space and the sync failed. Now I seem to have a bunch of local changes that are actually changes that were being pulled from origin. I tried to run git pull but got:
C:\Users\Tom\SourceLog [master +4 ~26 -0 !]> git pull Updating b3a86e1..5afd74f error: Your local changes to the following files would be overwritten by merge: SourceLog.Interface/IChangedFile.cs SourceLog.Interface/ILogEntry.cs ... Please, commit your changes or stash them before you can merge. error: The following untracked working tree files would be overwritten by merge: Lib/MSBuildExtensionPack/4.0.6.0/Ionic.Zip.dll Lib/MSBuildExtensionPack/4.0.6.0/MSBuild.ExtensionPack.dll ... Aborting
So now I'm trying to discard the local changes but I'm getting:
C:\Users\Tom\SourceLog [master +4 ~26 -0 !]> git checkout -- . Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) y Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) n fatal: unable to write new index file
How can I clean this up? (I didn't have any local changes before starting the sync.)
Update
Can't seem to reset head..
C:\Users\Tom\SourceLog [master +4 ~0 -0 !]> git reset head Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) y Rename from '.git/index.lock' to '.git/index' failed. Should I try again? (y/n) n error: Could not write new index file. fatal: Could not reset index file to revision 'head'.
-
James McDonnell over 11 yearsOr read here, this should work: stackoverflow.com/questions/3380805/…
-
Tom Hunter over 11 yearsThanks @JamesMcDonnell. Unfortunately it doesn't look like I can do this either.. (see my update).
-
James McDonnell over 11 yearsYou could delete your .git folder, create a new repo and pull.
-
BrainStone almost 11 yearsI guess it's not even required to do
git reset HEAD
. It worked for me without that! -
Rob over 10 yearsAgreed, I think it's just the ssh-agent.exe process that locks the index file. No need to do anything other than kill it.
-
Matt about 6 yearsWorked for me by deleting both .git/index and .git/index.lock
-
101 almost 6 yearsAh, also using Google Drive. Seems to go away after a second or two.
-
A. Blesius over 5 yearsHi, normally it shouldn't be necessary to specify
--mixed
, as it is the standard already: git-scm.com/docs/git-reset#git-reset---mixed -
Agilanbu over 5 yearstry to highlight the keywords and be clear with the format it will help to reach out your answer for others
-
Dimagog about 5 years@A.Blesius yes,
--mixed
is the default, but I made it explicit becausereset
command could look scary. -
Olov over 4 yearsI encountered the same problem, and the process which had a lock for me was Visual Studio Code (or something related to it), because when I shut it down, it worked as expected.
-
Lightning3 almost 4 years@DimagogThanks you so much for the tip. In my case: Visual studio in admin mode, and GitKraken in non-admin mode, so I got the message in GitKraken, because of permissions! Thanks!
-
Elliott Collins almost 4 yearsFor posterity, version conflicts in Dropbox can also cause this, but it won't go away on its own. In either case, the "conflicted copy" of .git/index just needs to be removed.
-
Daniel Butler over 3 yearsThis was my issue. The place that
.git
was located was in a protected folder -
Laurence about 3 yearsexactly what happened to me. but it's still a pain that I have to close vscode to do a git commit.
-
Heinrich Ulbricht almost 3 yearsFor me it was explorer.exe although I did not have the actual folder or any sub folder open. Closing all Explorer windows was enough to solve the problem for me.
-
Günter Zöchbauer over 2 yearsIn my case closing VSCode fixed it.
-
AlwaysLearning over 2 yearsAfter doing this, I was able to
git add .
, but got the error again when doinggit commit