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

git worktree loses path information after git reset --hard

From
DEDaniel Egger <daniel@eggers-club.de>
Date
Feb 8, 2016, 08:07 UTC
Message-ID
<A1270C54-3868-42F4-8F7E-8F444631078F@eggers-club.de>
Hi guys,
I stumbled across a problem with worktrees recently; I incorrectly opened a ticket a GitHub for that and it was suggested that it might be fixed in 2.7.1 so I held off reporting it here but as it turned out it is still broken in 2.7.1 so here we go.
The problem is that the paths of the worktrees in $GIT_DIR/worktrees/worktree_name/gitdir are rewritten to read .git instead of /path/to/worktree/root/.git after a git reset --hard (and potentially other operations) which causes all worktrees in git worktree list to point to the current worktree instead of the main repository path.
Let me demonstrate:

# git worktree list /Users/user/Desktop/Source/Product 2991e32 [master] /Users/user/Desktop/Source/Product-2.1 3fc1082 [releases/master-2.1] /Users/user/Desktop/Source/Product-2.2 3ccc3fe [releases/master-2.2] /Users/user/Desktop/Source/Product-2.3 4044881 [releases/master-2.3] # cd /Users/user/Desktop/Source/Product-2.1 # git reset --hard # cd /Users/user/Desktop/Source/Product-2.2 # git reset --hard # cd /Users/user/Desktop/Source/Product # git worktree list /Users/user/Desktop/Source/Product 2991e32 [master] /Users/user/Desktop/Source/Product 3fc1082 [releases/master-2.1] /Users/user/Desktop/Source/Product 3ccc3fe [releases/master-2.2] /Users/user/Desktop/Source/Product-2.3 4044881 [releases/master-2.3]

Servus,
      Daniel
Next: Junio C Hamano
Message 1 of 2 in “git worktree loses path information after git reset --hard”
  1. Daniel EggerFeb 8, 2016
  2. Junio C HamanoFeb 8, 2016

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.