{"thread":{"id":"63698","subject":"git rebase interactive breaks when working on a secondary worktree","startedAt":"2025-06-26T10:49:36Z","lastAt":"2025-06-27T11:42:44Z","messageCount":5,"participants":["Denilson Sá Maia","Kristoffer Haugsbakk","Phillip Wood"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"520752","messageId":"CACGt9y=WktE5Tqkxf6_tb_YnaeDyJTGYZoU7vErnSGnZMpuC-Q@mail.gmail.com","threadId":"63698","inReplyTo":null,"subject":"git rebase interactive breaks when working on a secondary worktree","fromName":"Denilson Sá Maia","fromEmail":"denilsonsa@gmail.com","sentAt":"2025-06-26T10:49:22Z","receivedAt":"2025-06-26T10:49:36Z","isPatch":false,"sender":{"key":"denilsonsa@gmail.com","avatar":"https://gravatar.com/avatar/bf5e1ba5bb693b2aaef4defc32b8776334de9cb67d2cb46af631846ffb2457ff?d=mp&s=160"},"body":"git rebase interactive breaks when working on a secondary worktree\n\n## What did you do before the bug happened?\n\n1. `git clone` a repository.\n2. `git worktree add` to have a second branch checked out in another directory.\n3. Continue working as normal. The main branch has a bunch of extra\ncommits (at the main worktree).\n4. At the second worktree, after a while, try `git rebase -i\nhash_of_a_few_commits_ago`, or `git rebase -i main` (where main is the\nmain branch at the main worktree).\n5. Approve the plan, even without any changes.\n\n## What did you expect to happen?\n\nIt should work.\n\n## What happened instead?\n\nI get this error:\n\n    error: Your local changes to the following files would be\noverwritten by checkout:\n\nFollowed by a list of several files that were NOT changed in my\nsecondary branch at my secondary worktree.\n\nWhat's more, if I redo the `git rebase` but without `-i`, it works\nfine without any errors.\n\n## What's different between what you expected and what actually happened?\n\nIf I try following the exact same steps (the exact same git rebase -i)\non the exact same branch, but this time having it checked out at the\nmain worktree, then everything works.\n\n## Anything else you want to add:\n\nI've been hitting this error for several months.\n\nIt doesn't happen every time, it depends on the commits from both\nbranches. Thus, it's hard for me to give you a minimal reproducible\nexample git repository.\n\nGiven the circumstances, I believe some part of the `git rebase\n--interactive` codepath is not working correctly with worktrees, and\nthus it's misbehaving.\n\n\n\n[System Info]\ngit version:\ngit version 2.49.0\ncpu: arm64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nfeature: fsmonitor--daemon\nlibcurl: 8.7.1\nzlib: 1.2.12\nuname: Darwin 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29\nPDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030 arm64\ncompiler info: clang: 17.0.0 (clang-1700.0.13.3)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n\n\n[Enabled Hooks]\napplypatch-msg\ncommit-msg\npost-applypatch\npost-checkout\npost-commit\npost-merge\npost-rewrite\npre-applypatch\npre-auto-gc\npre-commit\npre-merge-commit\npre-push\npre-rebase\nprepare-commit-msg\n\n\n-- \nDenilson Figueiredo de Sá Maia\nhttps://denilson.sa.nom.br/\n"},{"id":"520768","messageId":"bec18631-c0c5-4e8d-99ca-7f2bbdd5e88f@app.fastmail.com","threadId":"63698","inReplyTo":"CACGt9y=WktE5Tqkxf6_tb_YnaeDyJTGYZoU7vErnSGnZMpuC-Q@mail.gmail.com","subject":"Re: git rebase interactive breaks when working on a secondary worktree","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-06-26T15:57:47Z","receivedAt":"2025-06-26T15:58:19Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Thu, Jun 26, 2025, at 12:49, Denilson Sá Maia wrote:\n> [System Info]\n> git version:\n> git version 2.49.0\n> cpu: arm64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> feature: fsmonitor--daemon\n> libcurl: 8.7.1\n> zlib: 1.2.12\n> uname: Darwin 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29\n> PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030 arm64\n> compiler info: clang: 17.0.0 (clang-1700.0.13.3)\n> libc info: no libc information available\n> $SHELL (typically, interactive shell): /bin/zsh\n>\n>\n> [Enabled Hooks]\n> applypatch-msg\n> commit-msg\n> post-applypatch\n> post-checkout\n> post-commit\n> post-merge\n> post-rewrite\n> pre-applypatch\n> pre-auto-gc\n> pre-commit\n> pre-merge-commit\n> pre-push\n> pre-rebase\n> prepare-commit-msg\n\nA lot of hooks. Do you use git-branchless?\n"},{"id":"520778","messageId":"CACGt9ymuLOaA7dK-Y-g0WR99EKgknsuXzOpEd8xqpNOpcK_38A@mail.gmail.com","threadId":"63698","inReplyTo":"bec18631-c0c5-4e8d-99ca-7f2bbdd5e88f@app.fastmail.com","subject":"Re: git rebase interactive breaks when working on a secondary worktree","fromName":"Denilson Sá Maia","fromEmail":"denilsonsa@gmail.com","sentAt":"2025-06-26T18:33:02Z","receivedAt":"2025-06-26T18:33:15Z","isPatch":false,"sender":{"key":"denilsonsa@gmail.com","avatar":"https://gravatar.com/avatar/bf5e1ba5bb693b2aaef4defc32b8776334de9cb67d2cb46af631846ffb2457ff?d=mp&s=160"},"body":"On Thu, 26 Jun 2025 at 17:58, Kristoffer Haugsbakk\n<kristofferhaugsbakk@fastmail.com> wrote:\n>\n> On Thu, Jun 26, 2025, at 12:49, Denilson Sá Maia wrote:\n> >\n> > [Enabled Hooks]\n> > applypatch-msg\n> > commit-msg\n> > post-applypatch\n> > post-checkout\n> > post-commit\n> > post-merge\n> > post-rewrite\n> > pre-applypatch\n> > pre-auto-gc\n> > pre-commit\n> > pre-merge-commit\n> > pre-push\n> > pre-rebase\n> > prepare-commit-msg\n>\n> A lot of hooks. Do you use git-branchless?\n\nWe are using Husky in our corporate/enterprise/business application.\nAnd I think husky hooks itself into all git hooks, and that's why I\nhave so many of them.\nhttps://github.com/typicode/husky\n\nBut inside our `.husky/` directory inside our git repository we only\nhave `commit-msg` and `pre-push` hooks configured. Everything else is\nunused. (Which probably means Husky gets called, but does absolutely\nnothing.)\n\n\n-- \nDenilson Figueiredo de Sá Maia\nhttps://denilson.sa.nom.br/\n"},{"id":"520805","messageId":"073cffb5-7f15-4c41-a7ac-9f8ad1f4fffd@gmail.com","threadId":"63698","inReplyTo":"CACGt9y=WktE5Tqkxf6_tb_YnaeDyJTGYZoU7vErnSGnZMpuC-Q@mail.gmail.com","subject":"Re: git rebase interactive breaks when working on a secondary worktree","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-06-27T09:52:32Z","receivedAt":"2025-06-27T09:52:36Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 26/06/2025 11:49, Denilson Sá Maia wrote:\n> git rebase interactive breaks when working on a secondary worktree\n> \n> ## What did you do before the bug happened?\n> \n> 1. `git clone` a repository.\n> 2. `git worktree add` to have a second branch checked out in another directory.\n> 3. Continue working as normal. The main branch has a bunch of extra\n> commits (at the main worktree).\n> 4. At the second worktree, after a while, try `git rebase -i\n> hash_of_a_few_commits_ago`, or `git rebase -i main` (where main is the\n> main branch at the main worktree).\n> 5. Approve the plan, even without any changes.\n> \n> ## What did you expect to happen?\n> \n> It should work.\n> \n> ## What happened instead?\n> \n> I get this error:\n> \n>      error: Your local changes to the following files would be\n> overwritten by checkout:\n> \n> Followed by a list of several files that were NOT changed in my\n> secondary branch at my secondary worktree.\n\nDo you have any line ending or filter attributes set on those files? \nAnother possibility is that we're failing to refresh the index before \nthe checkout. Looking at the code the index is definitely refreshed \nbefore the checkout when '--autostash' is given but I'm not sure it is \notherwise.\n\n> What's more, if I redo the `git rebase` but without `-i`, it works\n> fine without any errors.\n> \n> ## What's different between what you expected and what actually happened?\n> \n> If I try following the exact same steps (the exact same git rebase -i)\n> on the exact same branch, but this time having it checked out at the\n> main worktree, then everything works.\n> \n> ## Anything else you want to add:\n> \n> I've been hitting this error for several months.\n> \n> It doesn't happen every time, it depends on the commits from both\n> branches. Thus, it's hard for me to give you a minimal reproducible\n> example git repository.\n\nUnfortunately that makes it hard to figure out what is wrong.\n\n> Given the circumstances, I believe some part of the `git rebase\n> --interactive` codepath is not working correctly with worktrees, and\n> thus it's misbehaving.\n\nI'd be surprised if the fact that it was a secondary worktree was the \nproblem. Is the worktree on the same file system as the main repository? \nIs the worktree synced to a cloud service?\n\nThanks\n\nPhillip\n\n> \n> \n> [System Info]\n> git version:\n> git version 2.49.0\n> cpu: arm64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> feature: fsmonitor--daemon\n> libcurl: 8.7.1\n> zlib: 1.2.12\n> uname: Darwin 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29\n> PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030 arm64\n> compiler info: clang: 17.0.0 (clang-1700.0.13.3)\n> libc info: no libc information available\n> $SHELL (typically, interactive shell): /bin/zsh\n> \n> \n> [Enabled Hooks]\n> applypatch-msg\n> commit-msg\n> post-applypatch\n> post-checkout\n> post-commit\n> post-merge\n> post-rewrite\n> pre-applypatch\n> pre-auto-gc\n> pre-commit\n> pre-merge-commit\n> pre-push\n> pre-rebase\n> prepare-commit-msg\n> \n> \n\n"},{"id":"520806","messageId":"CACGt9ym5+YFGMvqN_mnfa8T_+0u3asXWeCrD-SstvQxfmN1aOg@mail.gmail.com","threadId":"63698","inReplyTo":"073cffb5-7f15-4c41-a7ac-9f8ad1f4fffd@gmail.com","subject":"Re: git rebase interactive breaks when working on a secondary worktree","fromName":"Denilson Sá Maia","fromEmail":"denilsonsa@gmail.com","sentAt":"2025-06-27T11:42:30Z","receivedAt":"2025-06-27T11:42:44Z","isPatch":false,"sender":{"key":"denilsonsa@gmail.com","avatar":"https://gravatar.com/avatar/bf5e1ba5bb693b2aaef4defc32b8776334de9cb67d2cb46af631846ffb2457ff?d=mp&s=160"},"body":"On Fri, 27 Jun 2025 at 11:52, Phillip Wood <phillip.wood123@gmail.com> wrote:\n>\n> Do you have any line ending or filter attributes set on those files?\n\nNot sure. How can I check that?\n\nI see this on the `local_repo_clone/.git/config`:\n\n[core]\n    repositoryformatversion = 0\n    filemode = true\n    bare = false\n    logallrefupdates = true\n    ignorecase = true\n    precomposeunicode = true\n    hooksPath = .husky/_\n\nI tried removing all of the options (except for\nrepositoryformatversion, as I'm scared to remove it).\nThe bug is still reproducible in such case. Thus, I'm sure it is not\nrelated to these options.\n\n> > It doesn't happen every time, it depends on the commits from both\n> > branches. Thus, it's hard for me to give you a minimal reproducible\n> > example git repository.\n>\n> Unfortunately that makes it hard to figure out what is wrong.\n\nHow to reproduce (approximate steps):\n\n1. The `main` branch is checked out at the directory `mainDir`.\n2. Create a new worktree at `secondaryDir` for the branch `secondary`.\n3. Make one or more commits on `secondary` that change a file `foo`.\n4. Make a handful of commits on `main` that change unrelated files.\n5. Back to `secondaryDir`, run `git rebase -i main`. (The `-i`\nparameter is important to reproduce this bug.)\n6. It will show a single commit to be picked. Accept the rebase plan\n(save and quit the editor).\n\nWhat happens:\n\nerror: Your local changes to the following files would be overwritten\nby checkout:\n        [It lists all the files changed by the newer commits from the\nmain branch.]\nPlease commit your changes or stash them before you switch branches.\nAborting\nerror: could not detach HEAD\n\n\nAlso, the latest commits from `main` don't need to be checked out on\n`mainDir`. This bug is also reproducible if `origin/main` has newer\ncommits, but the local `main` doesn't yet. In this case, run `git\nrebase -i origin/main` from within the secondary branch/directory.\n\nHopefully these reproduction steps work better. It seems to happen\nrelatively often (dare I say… consistently?) in this large repository\nfrom the application I'm working on. But I admit I haven't tried yet\nto reproduce it on a brand-new repository.\n\n\n> I'd be surprised if the fact that it was a secondary worktree was the\n> problem. Is the worktree on the same file system as the main repository?\n\nYes, same filesystem. Both worktrees are siblings under the same\nparent directory.\n\n> Is the worktree synced to a cloud service?\n\nIt's a local-only filesystem, not synced to anywhere else. (Except\nfor, obviously, `git push` and `git pull`.)\n\n\n-- \nDenilson Figueiredo de Sá Maia\nhttps://denilson.sa.nom.br/\n"}]}