lazygit: fatal: Unable to create `../index.lock`: File exists.
For some time now lazygit seems to bug all the time. I’m 100% sure that there are no other programs running in the background that could do some git operations.
I try to open lazygit from the terminal, but everytime I try to do any operation after that I get the error about the git lock. So I remove it by hand rm -rf .git/index.lock and get back to lazygit, same thing.
It doesn’t matter if I do this from bare console or from the console inside neovim. Sometimes after deleting the index.lock file and getting back it works fine, only to complain again a usage later.
If I remove the file manually and then use git commands instead of using lazygit, everything works fine.

Windows, but I’m on WSL2 kali-linux Linux stacjonarny 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 GNU/Linux
Lazygit version 0.34
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 18
- Comments: 77 (16 by maintainers)
Still meet this issue on 0.40.2.
My experience is that when this lock window appear, I exit lazygit, delete the
index.lockfile, and enter lazygit, then:a, the lock window won’t appear. Then if I hitaagain to unstage, and stage one file, the lock window won’t appear.Still seeing this in 0.40.2 as well. Will this issue be re-open again?
Still seeing this in 0.40.2 as well.
I have seen the error twice in the last two or three weeks, this is not often enough to be able to investigate. On average, I’d estimate that I see it once every three months, maybe.
For those who see it really often (@richard-vock): I have made patches to both git and lazygit that add some logging, this could hopefully help figure out what’s going wrong. To use these, you’d have to build both git and lazygit from source.
The git patch is at https://github.com/stefanhaller/git/tree/hack-log-index-lock. To use it, clone
git@github.com:stefanhaller/git.git, check out the branchhack-log-index-lock, and build using something likeFeel free to use a more suitable directory than /tmp of course, but if you use something in your home directory, note that using a tilde in
prefix=~/whateverdoesn’t work for some reason, you need the full absolute path there.The lazygit patch is at https://github.com/jesseduffield/lazygit/tree/hack-log-command-pids. To use it, clone the lazygit repo, check out the branch
hack-log-command-pids, and build using something likemake build.Then, run lazygit using
PATH=/tmp/git-log-hack/bin:$PATH ./lazygit. This will create a log file in/tmp/git.logthat both git and lazygit log to. If you get the error, post the relevant section of the log file here.The patches should work on Mac and Linux, but probably not on Windows (I haven’t tried, and building git on Windows is a bit of a pain anyway).
I am hitting this issue roughly once per minute on 0.41.0 and 0.51.1. Tell me if I can help testing something.
I’m pretty regularly seeing similar behavior to https://github.com/jesseduffield/lazygit/issues/2050#issuecomment-2791398027 but rather bizarrely removing the lock file then running
git add --alldirectly in the terminal, THEN opening lazygit again doesn’t seem to re-create the lock file. Even though other commands don’t affect lazygit at all.When this starts happening:
rm ./git/index.locklazygitEven some git commands do nothing:
rm ./git/index.lockgit fetchlazygitbut
git add“shakes things loose” for some reason:rm ./git/index.lockgit add --alllazygitgit resetthenlazygitand it’s fine.Unfortunately this is just an effect, not a primary cause: lazygit is just retrying on lock
https://github.com/jesseduffield/lazygit/blob/66caa25dcd4c247589e6adc71a6bc088678f3212/pkg/commands/git_cmd_obj_runner.go#L31-L37
I ran into the same issue. I use the following workaround: In my
~/.config/lazygit/config.yml, I disabled the auto-fetch functionality via:The downside of this approach is that I always have to manually fetch the latest changes from a remote, but I never ran into the
index.lockissue again.As this workaround resolves it, I would assume the issue itself is somewhat related to the auto-fetching functionality.
This issue started popping up this year for me, I’m surprised to see it’s long history. For some reason lazygit creates the index.lock on startup and never releases it. It has happened in multiple repo’s now, and when it is triggered it’s only solved by removing the lockfile, making sure I have no local changes using another git tool and then restarting (I actually just give up on lazygit for the day when it occurs and pray is doesn’t break tomorrow)
I tried removing the entire index file once which did work
I hadn’t thought about using inotify/fswatch, because I had not heard of them 😅 Maybe should have looked for an existing solution before trying to write my own thing.
Either way, I have come to the belief that the
git status --untracked-files=all --porcelain -z --find-renames=50%is what is acquiring the lock. If I replace this line with a static empty slice, then a lock is never acquired, and there is no git status in the log, and it lines up with the timing. The question still remains what could cause this function to not release the lock sometimes.https://github.com/jesseduffield/lazygit/blob/391654984b854de32703a9ea30234d79aeff6e3b/pkg/gui/controllers/helpers/refresh_helper.go#L574-L577
Great work @ChrisMcD1 👍 Have you tough about using inotify/fswatch instead polling 1k/sec? It should increase time resolution even further.
I have been getting seemingly very lucky and can reproduce this issue with my exact setup. Here’s the full startup logs that acquire the lock and then never release it.
I did this with an additional commit that added nanosecond precision to debug logging, and I know the log file appeared here:
which places it somewhere in the vicinity of these lines:
(Reminder for all viewing that all commands are run with
GIT_OPTIONAL_LOCKS=0, I believe.)I have now lost the ability to reproduce, even though I believe I am running the same commands, but hopefully these logs with precise timestamps can help!
I was just lucky enough to have this error show up! (That’s not really a joke, I would love to solve this, but need to reproduce it as a first step).
I was unfortunately unable to consistently reproduce it. Here is my recollection of what happened.
go generate ./...go run main.gogit.autoRefresh: falsetrue, and relaunching, I am once again unable to reproduce the problem. No lock is acquired on startup, even with autofetch on.I don’t think this gives us any particular new insights into how to consistently reproduce, but just thought I would share!
This is happening to me (regularly, in
0.41.0) when I attempt to discard changes on a deleted file. I can work around it by leavinglazygit, deleting the lock file (which is in a worktree directory, eg:../.bare/worktrees/foo/index.lock), and then invokinggitwithcheckoutto restore the file.@owzim This workaround may save you from cloning your repo again.
Ah damn, that’s a bug in lazygit. It tends to read both stdout and stderr most of the time, instead of just stdout. We fixed one specific occurrence of this problem in 438038a4f1, but there are many others, and fixing them all is probably a lot of work. Plus, if we do it in the way it was done in 438038a4f1 then it wouldn’t help at all, because there we just swallow stderr instead of printing it to some log.
@jorgheymans Thanks for that. It doesn’t tell me much more, -17 seems to indicate that the git process died on a SIGSTOP signal, and I don’t know what to make of that. Maybe someone with more Unix knowledge can figure out more?
It seems that it’s lazygit itself that creates the
.git/index.lockfile. I thought that maybe it’s related to the version of git running on my system (Ubuntu LTS) but it’s not the case. It’s happening with both the LTS version2.37as well as latest2.43.2.I setup an audit for the file:
sudo auditctl -w /path/to/.git/index.lock -p w -k git-index-lockThen when the bug is triggered i can see this :
ausearch git-index-lockWhat may give a hint is that
/usr/bin/gitexited with code -17 ?It happened in my environment (macOS) even with v0.34.
It seemed to be caused by tmux’s
pane-border-format(with git status) that was updating every second.Welp, fun while it lasted
Uhhh, well then… try updating? 😅