git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Parallel worktree checkouts result in index.lock exists

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 22, 2023, 00:06 UTC
Message-ID
<Y/VcbWogtHrpXU8Z@tapette.crustytoothpaste.net>
In-Reply-To
<Y/UAaC4oBPIby4kV@google.com>
On 2023-02-21 at 17:33:28, Raul E Rangel wrote:
Show 25 quoted lines
> Hello,
> I'm trying to extract multiple trees in parallel so I can create a
> tarball of the trees. I can't use `git archive` since it doesn't
> currently produce hermetic output, and I need to support older git
> versions.
> 
> In essence what I'm trying to do is:
> 
>     git --work-tree ~/tmp/bob1 checkout ff27f5415797ead8bc775518a08f3a4ab24abd53 -- . &
>     git --work-tree ~/tmp/bob2 checkout e70ebd7c76b9f9ad44b59e3002a5c57be5b9dc12 -- . &
> 
> When I do this though, I get the following error:
>     [1] 4027482
>     [2] 4027483
>     fatal: Unable to create '/home/rrangel/cros-bazel/.repo/project-objects/chromiumos/platform/vboot_reference.git/./index.lock': File exists.
>     
>     Another git process seems to be running in this repository, e.g.
>     an editor opened by 'git commit'. Please make sure all processes
>     are terminated then try again. If it still fails, a git process
>     may have crashed in this repository earlier:
>     remove the file manually to continue.
> 
> Is this expected? I'm not sure why the index is coming into play here.
> Is there another method I should be using to extract a tree into a
> directory?

This is expected because when you do a checkout, the timestamps and other metadata of the files are written into the index. This is what makes `git status` work quickly: if the metadata of the files hasn't changed, Git doesn't have to re-read them to verify their contents. You definitely don't want to delete that because you'll likely end up with corrupt data.

If you want to create multiple worktrees, use `git worktree add`, which can create multiple worktrees that each have their own index, but share the object store. When you're done with it, run `git worktree remove`, and everything will be cleaned up.

Note that with worktrees, you can have at most one worktree with a given branch (or detached head) checked out at a time.

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Raul E RangelNext: Raul Rangel
Message 2 of 3 in “Parallel worktree checkouts result in index.lock exists”
  1. Raul E RangelFeb 21, 2023
  2. brian m. carlsonFeb 22, 2023
  3. Raul RangelMar 7, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.