Hi, I tried to minimize this but I haven't been able to come to a much smaller example. /David "kaddkaka" Moberg What did you do before the bug happened? (Steps to reproduce your issue) When doing `git rebase --exec` in a "secondary" worktree, it seems that there is confusion about where the repo root dir is. This sequence of commands can be run to reproduce: mktemp -d /tmp/git_bugreport_rebase_exec_worktree_root.XXXXXX cd /tmp/git_bugreport_rebase_exec_worktree_root.* mkdir repo cd repo/ mkdir dir echo -e 'lint:' > dir/Makefile echo -e '\tgit rev-parse --show-toplevel' >> dir/Makefile echo -e '\tgit grep "banana" -- "$$BANANA"' >> dir/Makefile git init git add dir git commit -m"Intial commit" git worktree add ../repo2 cd ../repo2/ BANANA=$PWD GIT_EDITOR='sed -i "1s/noop/exec make -C dir\/ lint/"' git rebase -i HEAD What did you expect to happen? (Expected behavior) 1. This command should return the worktree toplevel, not a subdirectory $ git rev-parse --show-toplevel /tmp/tmp.DUUAVQCIKe/repo2 2. And the git grep command should return the match from dir/Makefile, not Fatal Error $ git grep banana Makefile: git grep "banana" -- "$$BANANA" What happened instead? (Actual behavior) 1. --show-toplevel reports a subdirectory instead of toplevel: $ git rev-parse --show-toplevel /tmp/tmp.DUUAVQCIKe/repo2/dir 2. git grep complains that the pathspec is outside the repository with fatal error: $ git grep "banana" -- "$BANANA" fatal: /tmp/tmp.DUUAVQCIKe/repo2: '/tmp/tmp.DUUAVQCIKe/repo2' is outside repository at '/tmp/tmp.DUUAVQCIKe/repo2/dir' make: *** [Makefile:3: lint] Error 128 make: Leaving directory '/tmp/tmp.DUUAVQCIKe/repo2/dir' warning: execution failed: make -C dir/ lint What's different between what you expected and what actually happened? See above. [System Info] git version: git version 2.43.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): /usr/bin/bash [Enabled Hooks]