Skip to content

Allow relocating worktrees with unstaged changes #3103

Closed

Description

@lunaynx

wt step relocate currently refuses to relocate worktrees with unstaged changes. This feels like a pointless restriction, given that git worktree move is able to handle them just fine. The whole point of worktrees is that you don't have to commit or stash your changes before switching between them, so I don't see why it should be any different for relocating them. At the very least, there should be a -f/--force option even if you want to encourage committing first just in case.

Activity

  1. worktrunk-bot commented on Jun 17, 2026

    @worktrunk-bot
    Collaborator

    Thanks for the suggestion. I confirmed locally (git 2.54) that git worktree move happily moves a worktree with both modified-tracked files and untracked files, no --force needed — so the dirty-skip is purely a worktrunk policy, not a git limitation. The check lives in validate_candidates and just calls git status --porcelain to decide whether to skip.

    A few considerations for the design that a maintainer will want to weigh in on:

    • Default vs. opt-in flag. Worktrunk's Data Safety guideline prefers explicit consent for destructive-feeling operations, which would point toward a --force / --allow-dirty flag rather than changing the default. Moving the working copy isn't destructive per se, but it does relocate uncommitted work without a git reflog-style undo path.
    • Main worktree case is different. Relocating the main worktree can't use git worktree move — the code instead does git checkout <default-branch> on the main worktree and creates a new linked worktree at the expected path (see move_main_worktree). git checkout will refuse to switch branches if it would clobber uncommitted changes, so a --force flag would need to either skip dirty main worktrees with a warning or pass --force through to git checkout (which does lose data — different tradeoff).

    A maintainer will pick the right shape here.

    In the meantime, the closest existing escape hatch is wt step relocate --commit, which auto-commits dirty worktrees before relocating — not what you're asking for, but it does avoid manual stashing.

    A maintainer will take a closer look and prioritize.

  2. max-sixty commented on Jun 17, 2026

    @max-sixty
    Owner

    git worktree move is able to handle them just fine.

    that's a great point!

    @worktrunk-bot does that mean we can easily enable this, at least for non-main worktrees?

  3. worktrunk-bot commented on Jun 17, 2026

    @worktrunk-bot
    Collaborator

    Yes — for linked worktrees this is a one-line predicate change in validate_candidates, since git worktree move carries modified-tracked and untracked files along. Posted as #3104.

    The main worktree still has to skip when dirty: its relocation falls back to git checkout <default-branch>, which refuses to switch over uncommitted changes. The PR keeps that skip and tightens the warning to (uncommitted changes in main worktree) so the surviving case is clear, with --commit still the escape hatch.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions