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.

image

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)

Most upvoted comments

Still meet this issue on 0.40.2.

My experience is that when this lock window appear, I exit lazygit, delete the index.lock file, and enter lazygit, then:

  • If I stage one file by hitting space on one file, the lock window appears again.
  • If I stage all files by hitting a, the lock window won’t appear. Then if I hit a again 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 branch hack-log-index-lock, and build using something like

mkdir /tmp/git-log-hack
make -j9 prefix=/tmp/git-log-hack install

Feel 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=~/whatever doesn’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 like make build.

Then, run lazygit using PATH=/tmp/git-log-hack/bin:$PATH ./lazygit. This will create a log file in /tmp/git.log that 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 --all directly 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:

  1. exit lazygit
  2. rm ./git/index.lock
  3. lazygit
  4. index.lock is recreated, lazygit can’t do anything

Even some git commands do nothing:

  1. exit lazygit
  2. rm ./git/index.lock
  3. git fetch
  4. lazygit
  5. index.lock is recreated, lazygit can’t do anything

but git add “shakes things loose” for some reason:

  1. exit lazygit
  2. rm ./git/index.lock
  3. git add --all
  4. lazygit
  5. index.lock stays gone, problem disappears for a while. I can even git reset then lazygit and it’s fine.

It does usually happen for me when I’m staging a single file, at which point the git add command occurs 5 times in the command log.

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:

git:
  autoFetch: false

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.lock issue 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.

{"command":"git --version","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3668559-04:00"}
{"level":"info","msg":"git --version (1.3355ms)","time":"2025-04-09T22:58:35.3682999-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3685932-04:00"}
{"level":"info","msg":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree (2.5641ms)","time":"2025-04-09T22:58:35.3712031-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3736045-04:00"}
{"level":"info","msg":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --show-toplevel --absolute-git-dir --git-common-dir --is-bare-repository --show-superproject-working-tree (2.7021ms)","time":"2025-04-09T22:58:35.3764543-04:00"}
{"level":"info","msg":"starting main loop","time":"2025-04-09T22:58:35.3778567-04:00"}
{"level":"info","msg":"Current version is not built from an official release so we won't check for an update","time":"2025-04-09T22:58:35.3785233-04:00"}
{"level":"info","msg":"refreshing all scopes in async mode","time":"2025-04-09T22:58:35.379927-04:00"}
{"level":"info","msg":"Refresh took 140µs","time":"2025-04-09T22:58:35.3800699-04:00"}
{"command":"git stash list -z --pretty=%ct|%gs","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3802957-04:00"}
{"command":"git tag --list -n --sort=-creatordate","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3804822-04:00"}
{"command":"git rev-parse --abbrev-ref --verify HEAD","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3803188-04:00"}
{"command":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3804837-04:00"}
{"level":"debug","msg":"Error getting git config value for key: rebase.updateRefs. Error: the key is not found for [git config --get --null rebase.updateRefs]","time":"2025-04-09T22:58:35.3820958-04:00"}
{"level":"info","msg":"git rev-parse --abbrev-ref --verify HEAD (1.8455ms)","time":"2025-04-09T22:58:35.3825618-04:00"}
{"command":"git merge-base 3961-all-branches-log 3961-all-branches-log@{u}","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3831522-04:00"}
{"command":"git rev-parse --symbolic-full-name main@{u}","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3837193-04:00"}
{"command":"git rev-parse --symbolic-full-name master@{u}","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3838696-04:00"}
{"level":"info","msg":"git merge-base 3961-all-branches-log 3961-all-branches-log@{u} (6.6516ms)","time":"2025-04-09T22:58:35.389838-04:00"}
{"level":"info","msg":"git tag --list -n --sort=-creatordate (9.4597ms)","time":"2025-04-09T22:58:35.3900069-04:00"}
{"level":"info","msg":"git rev-parse --symbolic-full-name master@{u} (8.0898ms)","time":"2025-04-09T22:58:35.3920571-04:00"}
{"command":"git rev-parse --symbolic-full-name main@{u}","level":"error","msg":"fatal: no such branch: 'main'\n","time":"2025-04-09T22:58:35.3952664-04:00"}
{"level":"info","msg":"git rev-parse --symbolic-full-name main@{u} (11.5576ms)","time":"2025-04-09T22:58:35.3953785-04:00"}
{"command":"git rev-parse --verify --quiet refs/remotes/origin/main","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.395639-04:00"}
{"level":"debug","msg":"Error getting git config value for key: status.showUntrackedFiles. Error: the key is not found for [git config --get --null status.showUntrackedFiles]","time":"2025-04-09T22:58:35.3953196-04:00"}
{"level":"info","msg":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads (15.0462ms)","time":"2025-04-09T22:58:35.3959439-04:00"}
{"level":"info","msg":"git stash list -z --pretty=%ct|%gs (15.0153ms)","time":"2025-04-09T22:58:35.395368-04:00"}
{"level":"info","msg":"Receiving focus - refreshing","time":"2025-04-09T22:58:35.3964955-04:00"}
{"level":"info","msg":"refreshing all scopes in async mode","time":"2025-04-09T22:58:35.3965408-04:00"}
{"level":"info","msg":"Refresh took 41µs","time":"2025-04-09T22:58:35.3965829-04:00"}
{"level":"info","msg":"git for-each-ref --sort=refname --format=%(refname:short) refs/remotes (15.8239ms)","time":"2025-04-09T22:58:35.3966192-04:00"}
{"command":"git status --untracked-files=all --porcelain -z --find-renames=50%","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3967581-04:00"}
{"command":"git stash list -z --pretty=%ct|%gs","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3968284-04:00"}
{"level":"info","msg":"postRefreshUpdate for remotes took 230.2µs","time":"2025-04-09T22:58:35.3969391-04:00"}
{"level":"info","msg":"postRefreshUpdate for remoteBranches took 4.5µs","time":"2025-04-09T22:58:35.3969764-04:00"}
{"command":"git tag --list -n --sort=-creatordate","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.3975108-04:00"}
{"command":"git rev-parse --verify --quiet refs/remotes/origin/main","level":"error","msg":"","time":"2025-04-09T22:58:35.4001593-04:00"}
{"level":"info","msg":"git rev-parse --verify --quiet refs/remotes/origin/main (4.5466ms)","time":"2025-04-09T22:58:35.4002195-04:00"}
{"command":"git rev-parse --verify --quiet refs/heads/main","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4003613-04:00"}
{"command":"git worktree list --porcelain","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4008402-04:00"}
{"command":"git rev-parse --verify --quiet refs/heads/main","level":"error","msg":"","time":"2025-04-09T22:58:35.4032729-04:00"}
{"level":"info","msg":"git rev-parse --verify --quiet refs/heads/main (2.9393ms)","time":"2025-04-09T22:58:35.4033205-04:00"}
{"level":"info","msg":"postRefreshUpdate for stash took 9.2254ms","time":"2025-04-09T22:58:35.4053491-04:00"}
{"command":"git merge-base HEAD refs/remotes/origin/master","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4059015-04:00"}
{"level":"info","msg":"git worktree list --porcelain (6.3804ms)","time":"2025-04-09T22:58:35.4072607-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --absolute-git-dir","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4074807-04:00"}
{"level":"info","msg":"postRefreshUpdate for tags took 17.324ms","time":"2025-04-09T22:58:35.4078399-04:00"}
{"level":"info","msg":"git tag --list -n --sort=-creatordate (14.1556ms)","time":"2025-04-09T22:58:35.4117199-04:00"}
{"level":"info","msg":"git merge-base HEAD refs/remotes/origin/master (6.1322ms)","time":"2025-04-09T22:58:35.4121-04:00"}
{"level":"info","msg":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --absolute-git-dir (8.1915ms)","time":"2025-04-09T22:58:35.4157231-04:00"}
{"level":"info","msg":"postRefreshUpdate for worktrees took 84.8µs","time":"2025-04-09T22:58:35.4158773-04:00"}
{"level":"info","msg":"git stash list -z --pretty=%ct|%gs (23.0226ms)","time":"2025-04-09T22:58:35.4199121-04:00"}
{"level":"info","msg":"postRefreshUpdate for stash took 101.4µs","time":"2025-04-09T22:58:35.4201019-04:00"}
{"level":"info","msg":"postRefreshUpdate for localBranches took 5.6141ms","time":"2025-04-09T22:58:35.4215283-04:00"}
{"level":"info","msg":"postRefreshUpdate for tags took 10.1178ms","time":"2025-04-09T22:58:35.4223482-04:00"}
{"level":"info","msg":"git -c log.showSignature=false log -g --abbrev=40 --format=%h%x00%ct%x00%gs%x00%p (43.627ms)","time":"2025-04-09T22:58:35.4241045-04:00"}
{"level":"info","msg":"git status --untracked-files=all --porcelain -z --find-renames=50% (27.3951ms)","time":"2025-04-09T22:58:35.4241854-04:00"}
{"level":"info","msg":"git for-each-ref --sort=refname --format=%(refname:short) refs/remotes (30.3317ms)","time":"2025-04-09T22:58:35.4276432-04:00"}
{"level":"info","msg":"postRefreshUpdate for remotes took 81.1µs","time":"2025-04-09T22:58:35.4278328-04:00"}
{"level":"info","msg":"postRefreshUpdate for remoteBranches took 5µs","time":"2025-04-09T22:58:35.4278765-04:00"}
{"level":"debug","msg":"Error getting git config value for key: status.showUntrackedFiles. Error: the key is not found for [git config --get --null status.showUntrackedFiles]","time":"2025-04-09T22:58:35.4279612-04:00"}
{"command":"git status --untracked-files=all --porcelain -z --find-renames=50%","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4281447-04:00"}
{"level":"info","msg":"postRefreshUpdate for submodules took 18.2µs","time":"2025-04-09T22:58:35.4297713-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit diff --no-ext-diff --submodule --unified=3 --color=always --find-renames=50% -- .","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4301619-04:00"}
{"level":"info","msg":"postRefreshUpdate for files took 556.7µs","time":"2025-04-09T22:58:35.4304266-04:00"}
{"level":"info","msg":"git status --untracked-files=all --porcelain -z --find-renames=50% (21.3476ms)","time":"2025-04-09T22:58:35.4495264-04:00"}
{"level":"info","msg":"postRefreshUpdate for submodules took 6.5µs","time":"2025-04-09T22:58:35.4496741-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit diff --no-ext-diff --submodule --unified=3 --color=always --find-renames=50% -- .","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4498823-04:00"}
{"level":"info","msg":"postRefreshUpdate for files took 227.3µs","time":"2025-04-09T22:58:35.4499171-04:00"}
{"level":"info","msg":"git -c log.showSignature=false log -g --abbrev=40 --format=%h%x00%ct%x00%gs%x00%p (54.4618ms)","time":"2025-04-09T22:58:35.4525414-04:00"}
{"level":"info","msg":"postRefreshUpdate for reflogCommits took 57.2941ms","time":"2025-04-09T22:58:35.4816507-04:00"}
{"level":"info","msg":"git log HEAD --topo-order --oneline --pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s --abbrev=40 -300 --no-show-signature -- (101.5213ms)","time":"2025-04-09T22:58:35.4849087-04:00"}
{"level":"debug","msg":"Error getting git config value for key: rebase.updateRefs. Error: the key is not found for [git config --get --null rebase.updateRefs]","time":"2025-04-09T22:58:35.4864822-04:00"}
{"level":"info","msg":"postRefreshUpdate for commits took 3.2022ms","time":"2025-04-09T22:58:35.4882662-04:00"}
{"command":"git rev-parse --abbrev-ref --verify HEAD","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4884834-04:00"}
{"level":"info","msg":"git rev-parse --abbrev-ref --verify HEAD (1.8241ms)","time":"2025-04-09T22:58:35.4903823-04:00"}
{"command":"git merge-base 3961-all-branches-log 3961-all-branches-log@{u}","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4907899-04:00"}
{"command":"git merge-base HEAD refs/remotes/origin/master","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4909552-04:00"}
{"level":"info","msg":"git merge-base HEAD refs/remotes/origin/master (5.2479ms)","time":"2025-04-09T22:58:35.4963613-04:00"}
{"level":"info","msg":"git merge-base 3961-all-branches-log 3961-all-branches-log@{u} (5.7366ms)","time":"2025-04-09T22:58:35.4966294-04:00"}
{"level":"info","msg":"postRefreshUpdate for reflogCommits took 47.7544ms","time":"2025-04-09T22:58:35.5008386-04:00"}
{"level":"info","msg":"git log HEAD --topo-order --oneline --pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s --abbrev=40 -300 --no-show-signature -- (60.1351ms)","time":"2025-04-09T22:58:35.5511363-04:00"}
{"level":"debug","msg":"using cache for key rebase.updateRefs","time":"2025-04-09T22:58:35.5514216-04:00"}
{"level":"info","msg":"postRefreshUpdate for commits took 379.2µs","time":"2025-04-09T22:58:35.5517936-04:00"}
{"level":"debug","msg":"using cache for key rebase.updateRefs","time":"2025-04-09T22:58:35.5518499-04:00"}
{"command":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.5528551-04:00"}
{"level":"info","msg":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads (9.5428ms)","time":"2025-04-09T22:58:35.5624851-04:00"}
{"command":"git worktree list --porcelain","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.5645018-04:00"}
{"level":"info","msg":"git worktree list --porcelain (1.4268ms)","time":"2025-04-09T22:58:35.5659719-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --absolute-git-dir","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.56614-04:00"}
{"level":"info","msg":"git -C /home/chrismcdonnell/linux-repos/lazygit rev-parse --absolute-git-dir (1.3684ms)","time":"2025-04-09T22:58:35.5675611-04:00"}
{"level":"info","msg":"postRefreshUpdate for worktrees took 24.9µs","time":"2025-04-09T22:58:35.5677569-04:00"}
{"level":"info","msg":"postRefreshUpdate for localBranches took 663.8µs","time":"2025-04-09T22:58:35.5684743-04:00"}
{"level":"debug","msg":"using cache for key rebase.updateRefs","time":"2025-04-09T22:58:35.568531-04:00"}
{"command":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.5689927-04:00"}
{"level":"info","msg":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads (7.8654ms)","time":"2025-04-09T22:58:35.5769209-04:00"}
{"level":"info","msg":"postRefreshUpdate for localBranches took 444.1µs","time":"2025-04-09T22:58:35.5795347-04:00"}
{"level":"debug","msg":"using cache for key rebase.updateRefs","time":"2025-04-09T22:58:35.5796357-04:00"}
{"command":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.5801254-04:00"}
{"level":"info","msg":"git for-each-ref --sort=-committerdate --format=%(HEAD)%00%(refname:short)%00%(upstream:short)%00%(upstream:track)%00%(push:track)%00%(subject)%00%(objectname)%00%(committerdate:unix) refs/heads (8.8057ms)","time":"2025-04-09T22:58:35.588985-04:00"}
{"level":"info","msg":"postRefreshUpdate for localBranches took 483.7µs","time":"2025-04-09T22:58:35.5919651-04:00"}
{"level":"debug","msg":"using cache for key rebase.updateRefs","time":"2025-04-09T22:58:35.5920597-04:00"}

I did this with an additional commit that added nanosecond precision to debug logging, and I know the log file appeared here:

[22:58:35.448] File appeared: /home/chrismcdonnell/linux-repos/lazygit/.git/index.lock

which places it somewhere in the vicinity of these lines:

{"command":"git status --untracked-files=all --porcelain -z --find-renames=50%","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4281447-04:00"}
{"level":"info","msg":"postRefreshUpdate for submodules took 18.2µs","time":"2025-04-09T22:58:35.4297713-04:00"}
{"command":"git -C /home/chrismcdonnell/linux-repos/lazygit diff --no-ext-diff --submodule --unified=3 --color=always --find-renames=50% -- .","level":"debug","msg":"RunCommand","time":"2025-04-09T22:58:35.4301619-04:00"}
{"level":"info","msg":"postRefreshUpdate for files took 556.7µs","time":"2025-04-09T22:58:35.4304266-04:00"}
{"level":"info","msg":"git status --untracked-files=all --porcelain -z --find-renames=50% (21.3476ms)","time":"2025-04-09T22:58:35.4495264-04:00"}

(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.

  1. I had just done a large rebase that moved my feature branch up ~130 commits.
  2. During that rebase, I had some conflicts.
  3. I partially resolved these conflicts via staging hunks in lazygit, and partially via manual edits in my editor
  4. The conflicts fully resolved.
  5. I closed lazygit, went to my terminal, did a go generate ./...
  6. I opened lazygit, went to stage my newly generated files, and ran into the index lock
  7. Closing lazygit did not remove the index lock. I at this point set up my tool to watch when the index lock showed up
  8. Launch lazygit, with default settings resulted in the lockfile being immediately required, prior to any user interaction. I closed lazygit, manually deleted the lockfile, and then relaunched lazygit, and it continued to immediately acquire it.
  9. Note, I was also able to recreate this behavior on master with a go run main.go
  10. Following the advice on this thread, I set git.autoRefresh: false
  11. Launching the lazygit with that set did not acquire the lock on startup
  12. After closing lazygit, setting that setting back to its default of true, 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 leaving lazygit, deleting the lock file (which is in a worktree directory, eg: ../.bare/worktrees/foo/index.lock), and then invoking git with checkout to restore the file.

Still meet this issue on 0.40.2.

My experience is that when this lock window appear, I exit lazygit, delete the index.lock file, and enter lazygit, then:

  • If I stage one file by hitting space on one file, the lock window appears again.
  • If I stage all files by hitting a, the lock window won’t appear. Then if I hit a again to unstage, and stage one file, the lock window won’t appear.

@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.lock file. 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 version 2.37 as well as latest 2.43.2.

I setup an audit for the file:

sudo auditctl -w /path/to/.git/index.lock -p w -k git-index-lock

Then when the bug is triggered i can see this :

ausearch git-index-lock

    │ time->Thu Mar  7 08:55:02 2024
  99   │ type=PROCTITLE msg=audit(1709798102.993:5255): proctitle=67697400616464002D2D006170702F66726F6E74656E642F7468656D65732F696D732F76696
       │ 57773
 100   │ type=PATH msg=audit(1709798102.993:5255): item=1 name="/path/to/repo/.git/index.lock" inode=11535492 dev=103:02 m
       │ ode=0100664 ouid=1000 ogid=1000 rdev=00:00 nametype=NORMAL cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
 101   │ type=PATH msg=audit(1709798102.993:5255): item=0 name="/path/to/repo/.git/" inode=11569583 dev=103:02 mode=040775
       │  ouid=1000 ogid=1000 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
 102   │ type=CWD msg=audit(1709798102.993:5255): cwd="/path/to/repo"
 103   │ type=SYSCALL msg=audit(1709798102.993:5255): arch=c000003e syscall=257 success=no exit=-17 a0=ffffff9c a1=5615a583ce60 a2=800c2 a3=1
       │ b6 items=2 ppid=2598205 pid=2598291 auid=1000 uid=1000 gid=1000 euid=1000 suid=1000 fsuid=1000 egid=1000 sgid=1000 fsgid=1000 tty=pt
       │ s0 ses=3 comm="git" exe="/usr/bin/git" subj=unconfined key="git-index-lock"

What may give a hint is that /usr/bin/git exited 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

image

Uhhh, well then… try updating? 😅