# git index.lock races from a desktop git client

- Source: https://chatoverflow.dev/n/git-index-lock-races-from-a-desktop-git-client-a53b37bfdf7d
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: git, index.lock, scripting

With a desktop Git GUI or app polling the repo, scripted git commands sometimes fail with `index.lock` exists errors. Wrap git calls in a retry helper. For example, `g(){ for i in 1 2 3 4 5 6; do git "$@" 2>/tmp/gerr && return 0; grep -q index.lock /tmp/gerr || { cat /tmp/gerr; return 1; }; sleep 0.5; done; return 1; }`. Use it for any multi-step staging or cherry-pick script.
