Skip to content

BranchPruner does not skip branches in use in worktrees #8043

Closed

Description

@koenpunt

Description

The branch pruner automatically deletes branches that have been merged in to the default branch. But with it, it also tries to delete branches that are checked out in separate worktrees, causing the command to fail.

I also think this causes the some other command to fail, because it now already happened multiple times that when I switch to a branch, the last commits on that branch appear as staged, but as revert (so to undo those changes). This is something I have to check and confirm tho.

Version

  • GitHub Desktop: 2.1.0
  • Operating system: macOS 10.14.5 (18F132)

Steps to Reproduce

  1. Open a terminal
  2. Navigate to a repository
  3. Create a new worktree git worktree add ../myrepo-2
  4. Wait at least 2 weeks (if you don't want to wait 2 week, you could also update the twoWeeksAgo definition in branch-pruner.ts instead).
  5. Open the original repository in GitHub Desktop

Expected Behavior

It should open the app and repository without issues

Actual Behavior

It shows an error dialog:
image

Nb. If it doesn't directly show, you might have to switch back and forth between repos in the app.

Activity

  1. shiftkey commented on Jul 29, 2019

    @shiftkey
    Member

    @koenpunt thanks for this report!

    I was hoping our worktrees wouldn't get caught up in these checks, but I guess we need to tweak or BranchPruner logic to be worktree-aware.

    Because the branch pruner works in the background, we should tweak the flow to perform this additional work:

    • look for branches open in any worktrees for this repository
    • exclude those from any branch pruner work, to avoid the error reported by Git

    #8006 adds some of our initial worktree support, and is currently under review. Once that's merged I plan to return to this and see what a potential solution might look like.

  2. added
    bug
    priority-3
    on Jul 29, 2019
  3. changed the title [-]BranchPruner does not consider branches in separate worktrees[/-] [+]BranchPruner does not skip branches in use in worktrees[/+] on Jul 29, 2019
  4. mesheets commented on Feb 15, 2024

    @mesheets

    Referencing #907, which is for better support for worktrees

  5. KRRT7 commented on Apr 24, 2026

    @KRRT7
    Contributor

    I have a fix for this ready with tests — PR #22004. Could a maintainer add the help wanted label so it doesn't get auto-closed?

    The fix adds git worktree list --porcelain parsing and excludes branches checked out in linked worktrees from the pruner's deletion set. 6 new tests, full suite passing.

  6. added a commit that references this issue on May 14, 2026
    135ad53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions