Skip to content

[feat]: Native workflow to merge worktree changes into main branch #528

@arnestrickmann

Description

@arnestrickmann

Feature Summary

Add a native workflow to merge completed worktree changes into the main branch without requiring pull requests. Allow users to "pop out" of the worktree context and operate an agent in the main branch to handle merging, conflict resolution, and cleanup.

Problem or Use Case

Currently, when a task is completed in a worktree:

  • No clear path to merge changes back into main within Emdash
  • Users must manually switch to main branch outside of Emdash
  • Merging feels disconnected from the worktree-based workflow
  • Pull request flow doesn't fit all workflows (solo developers, fast iteration, local-first
    development)
  • Context switching breaks the flow: worktree agent → manual terminal work → back to Emdash

For developers who don't use pull requests:

  • Working solo on personal projects
  • Rapid prototyping where PR overhead isn't justified
  • Local-first workflows where changes are reviewed before committing to worktree
  • Direct main branch development is standard practice

The worktree isolation is great for parallel work, but there's no elegant "merge back" step.

Proposed Solution

Implement a "Merge to Main" workflow that:

  1. Merge Button/Action:
    - Add "Merge to Main" button in workspace panel (when task complete)
    - Keyboard shortcut: Cmd+Shift+M (merge)
    - Shows confirmation dialog with summary of changes to merge
  2. Agent Context Switch:
    - Temporarily "pop out" of worktree context
    - Spawn agent operating in main branch (base repo, not worktree)
    - Agent has access to worktree branch changes
    - Clear UI indication: "Agent operating in main branch"
  3. Merge Flow:
    User clicks "Merge to Main" in worktree workspace
    → Confirmation dialog:
    - "Merge feature-auth branch into main?"
    - Shows commit summary from worktree
    - Option: "Review changes first" (opens diff)
    → Agent switches context to main branch
    → Agent executes merge:
    - git checkout main
    - git pull (ensure main is up to date)
    - git merge feature-auth
    - Handle conflicts if any (interactive with user)
    - git push (optional, configurable)
    → Success: Show merge summary
    → Cleanup options:
    - "Delete worktree" (remove feature branch worktree)
    - "Keep worktree" (continue working)
    - "Archive workspace" (mark as completed in Emdash)
  4. Conflict Resolution:
    - If merge has conflicts, agent guides user through resolution
    - Show conflict files in diff viewer
    - Agent can suggest resolutions or apply user decisions
    - Continue merge after conflicts resolved
  5. Post-Merge Options:
    - Automatic worktree cleanup (optional setting)
    - Return to main workspace view or stay in worktree
    - Create new worktree for next task
    - Show merge success notification with commit hash

Alternatives Considered

Alternatives Considered:

  1. Manual terminal merging (current state):
    - Context switching breaks flow
    - Easy to forget worktree cleanup
    - No agent assistance
    - Already possible but not integrated
  2. Force PR workflow:
    - Overhead for solo developers
    - Requires GitHub/GitLab setup
    - Not all projects use PR model
    - Doesn't fit fast iteration workflows
  3. Auto-merge on task completion:
    - Too aggressive, removes user control
    - No review step
    - Risk of merging incomplete work
  4. Merge command in terminal panel:
    - Still requires manual git commands
    - No agent assistance
    - Error-prone for complex merges

Additional Context

From Joe on X

UI/UX Considerations:

  • Clear visual distinction between worktree agent and main branch agent
  • Merge dialog shows:
    • Source branch (from worktree)
    • Target branch (main or custom)
    • Commit summary
    • Files changed count
  • Progress indicator during merge operation
  • Success/failure notifications with actionable next steps

Git Safety:

  • Never force push to main
  • Always check main is up to date before merge (git pull)
  • Respect git hooks and pre-merge checks
  • Rollback option if merge fails
  • Warn if local changes exist in base repo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions