git worktree loses path information after git reset --hard

From: Daniel Egger <hidden>
Date: 2016-06-15 23:08:09

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help