Skip to content

Worktrees: branches held by another worktree are unmarked and fail to check out #629

Closed

Description

@goneng

@hannesa2, GitX has no notion of worktrees at all - grep -ri worktree Classes finds nothing. Three things follow from that.

1. A branch checked out in another worktree looks like any other branch. git marks these itself: git branch prints + feature and colors it, and git worktree list gives the full picture. GitX shows it as an ordinary, checkout-able branch. The sidebar already badges HEAD with a checkmark, so there is a natural place for a marker.

2. Checking one out fails, and the message blames the wrong thing. git refuses by design:

fatal: 'feature' is already used by worktree at '/path/to/wt'

GitX drops that and shows a canned guess:

if (!output) {
NSString *title = @"Checkout failed";
NSString *message = [NSString stringWithFormat:@"There was an error checking out the %@ '%@'.\n\nPerhaps your working directory is not clean?", [ref refishType], [ref shortName]];
return PBReturnError(error, title, message, gitError);
}

So you are told "Perhaps your working directory is not clean?" and go hunting for uncommitted changes that do not exist. git's own text does reach the sheet further down, under "Output:", but the headline contradicts it. The same canned sentence is used for any failure of checkoutFiles:fromRefish: (L966) and cherryPickRefish: (L1007).

3. There is nothing to do about it in the app - no way to see where that worktree is, and no way to open it.

Suggested slices, smallest first:

  • show git's own message instead of the guess when the task fails. Self-contained, worth doing whether or not the rest happens.
  • read git worktree list --porcelain (path, HEAD, branch, locked/prunable in one call) and mark branches held by another worktree the way git does
  • for those branches, replace Checkout with "Open Worktree", opening that path as another GitX document
  • later: a WORKTREES section in the sidebar next to SUBMODULES, then add/remove

Note objective-git wraps none of this - libgit2 has git_worktree_list, ObjectiveGit never exposed it - but shelling out matches how checkout, stash and the rest already work.

Activity

  1. hannesa2 commented on Sep 13, 2026

    @hannesa2
    Contributor

    I personally don't use git worktrees at all.
    If you mean, that it's worth to jump into this: go ahead !

    Just in general what I see as a higher goal:

  2. goneng commented on Sep 13, 2026

    @goneng
    CollaboratorAuthor

    I personally don't use git worktrees at all. If you mean, that it's worth to jump into this: go ahead !

    Just in general what I see as a higher goal:

    * bump libgit2, I already tried it [Bump libgit2 to 1.0.0 #513](https://github.com/gitx/gitx/pull/513) [Bump libgit2 to 1.8.5 #509](https://github.com/gitx/gitx/pull/509) but I failed
    
    * move step by step into the direction of a full Swift project
    

    Great, so I'll just see if we can have some basic support for git-worktrees (maybe just label them with a different color, to make it clearer in the UI), then try to bump libgit2 and see where it get me...

  3. added a commit that references this issue on Sep 13, 2026
  4. self-assigned this
    on Sep 13, 2026
  5. added a commit that references this issue on Sep 15, 2026
  6. goneng commented on Sep 18, 2026

    @goneng
    CollaboratorAuthor

    Status update, since three of the four suggested slices have landed:

    • Show git's own message instead of the guess - Fix checkout errors blaming the working directory (issue #629) #630 (110ad547). -failureReasonFromTaskError:orFallback: prefers the failed task's own output and falls back to the canned sentence only when git said nothing. It covers all three call sites named above: checkoutRefish:, checkoutFiles:fromRefish: and cherryPickRefish:.
    • Mark branches held by another worktree - Add basic support for worktree branches (issue #629) #633 (e48132cb, f7470251). git worktree list --porcelain is read once per refs reload, the sidebar swaps in a WorktreeBranch icon for a held branch, and the details page is given the same list.
    • Replace Checkout with "Open Worktree" - Add basic support for worktree branches (issue #629) #633. For a branch another worktree holds, the contextual menu offers Open Worktree of Branch "name", with the worktree's path as its tooltip, in place of Checkout.
    • A WORKTREES section in the sidebar, next to SUBMODULES, and add/remove.

    Landed on top of those: #656 moved the worktree lookup off the drawing path (#647), so reading it no longer stalls the history while it draws.

    That leaves the last bullet as the only open work here. It may be worth splitting it into its own issue: the first three were what made the app actively misleading, while a sidebar section with add and remove is a feature rather than a fix, and keeping this one open makes the fixed parts look unfixed.

  7. goneng commented on Sep 18, 2026

    @goneng
    CollaboratorAuthor

    The remaining bullet is now #675, so everything tracked here has landed: #630 for the error message, #633 for the marking and the Open Worktree action, and #656 for taking the lookup off the drawing path.

  8. goneng commented on Sep 18, 2026

    @goneng
    CollaboratorAuthor

    Closing: the three slices filed here are done, and the fourth is now tracked in #675.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions