Skip to content

feat: support git worktrees when checking out PRs#794

Open
sideshowbarker wants to merge 1 commit intodlvhdr:mainfrom
sideshowbarker:feat/worktree-checkout
Open

feat: support git worktrees when checking out PRs#794
sideshowbarker wants to merge 1 commit intodlvhdr:mainfrom
sideshowbarker:feat/worktree-checkout

Conversation

@sideshowbarker
Copy link
Copy Markdown
Contributor

@sideshowbarker sideshowbarker commented Mar 6, 2026

Add a new worktreePaths config key that enables linked worktree checkouts. When a repository matches a worktreePaths entry, pressing C or Space (checkout) creates a linked worktree named after the PR branch — rather than switching branches in the clone directory. Fixes #544.

How it works

  • repoPaths → the clone directory where git worktree add gets run
  • worktreePaths → a worktrees directory where linked worktrees are created as subdirectories, one per PR branch

Both must be configured for the same repository or template pattern. Example:

repoPaths:
  dlvhdr/gh-dash: ~/code/dlvhdr/gh-dash

worktreePaths:
  dlvhdr/gh-dash: ~/code/dlvhdr/gh-dash/.worktrees

Behavior

  • New PR: Creates a linked worktree and checks out the PR branch inside it
  • Existing worktree: Skips creation, copies the path to the clipboard
  • Checkout failure: Automatically cleans up the partially created worktree
  • Repo not cloned: Shows an error asking to clone the repository first
  • Missing repoPaths: Shows an error explaining that both settings are required
  • Command errors: stderr is now captured and included in error messages (previously only showed “exit status 1”)

On success, the linked-worktree path is copied to the clipboard.

Note

This all also works in bare repo worktree workflows (where even the main branch is a linked worktree), as long as repoPaths points not to a .bare directory but to an actual clone directory containing a .bare|.git directory.

Code/test/docs/config notes

  • Extracts checkout logic into a shared common.CheckoutPR() function used by both the PR and Notification dashboards (previously duplicated)
  • Passes on, to the UI, more-detailed error messages from gh/git for checkout failures (RunCommandFunc now captures stderr from gh/git)
  • Adds user docs, and updates the config parser, JSON/YAML schemas, example configs, and golden test files to add worktreePaths
  • Adds test coverage for all the new behavior and possible error/failure scenarios

@sideshowbarker sideshowbarker force-pushed the feat/worktree-checkout branch 3 times, most recently from ab570b0 to dbfac76 Compare March 8, 2026 19:15
Copy link
Copy Markdown
Owner

@dlvhdr dlvhdr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for creating hte pr

@sideshowbarker sideshowbarker force-pushed the feat/worktree-checkout branch from dbfac76 to 1a35305 Compare March 11, 2026 22:37
@sideshowbarker sideshowbarker force-pushed the feat/worktree-checkout branch from 1a35305 to ec7387d Compare March 23, 2026 11:39
Fixes dlvhdr#544

Add a new worktreePaths config key that enables git worktree-based
checkouts. When a repository matches a worktreePaths entry, pressing
checkout (C/Space) creates a worktree subdirectory named after the PR
branch — rather than switching branches in place. On success, the
worktree path is copied to the clipboard.

If the worktree already exists, Dash skips creation and copies the path.
If “gh pr checkout” fails inside a new worktree, the worktree is
automatically cleaned up.

This change also extracts/consolidates the PR-checkout code into a
shared common.CheckoutPR() function used by both the PR dashboard and
Notification dashboard — avoiding code duplication.
@sideshowbarker sideshowbarker force-pushed the feat/worktree-checkout branch from ec7387d to 0e14b8f Compare March 25, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for git worktrees when checking out

2 participants