Skip to main content
GWTree provides commands to merge your work back to the main branch and automatically clean up worktrees when they’re no longer needed.

Merge Command

Merge a worktree’s branch to main and remove the worktree:

Finding Worktrees by Name

The merge command accepts different name formats:
GWTree searches for matches in this order:
  1. Exact branch name match
  2. Worktree directory name match
  3. Worktree suffix match (without repo prefix)

Merge Workflow

Merge Failures

Uncommitted Changes

Solution: Commit or stash changes before merging.

Merge Conflicts

Solution:
  1. The main repository is left in a conflicted state
  2. Navigate to the main repo
  3. Resolve conflicts manually
  4. Complete the merge with git commit
  5. Remove the worktree manually with gwt rm

Clean Command

Automatically remove worktrees that have been merged to main:

Clean Merged Worktrees

By default, gwt clean removes only merged worktrees:

How Merge Detection Works

GWTree determines if a worktree is merged by running:
A worktree is considered merged if its branch appears in this list.

Clean All Worktrees

Remove ALL worktrees regardless of merge status:
Using --all removes worktrees even if they have:
  • Uncommitted changes
  • Unpushed commits
  • Unmerged work
Make sure to review your worktrees with gwt status first.

Clean Workflow

No Worktrees to Clean

If no worktrees match the criteria:
Combine commands for an efficient workflow:

1. Check Status

See which worktrees are ready:
Output:

2. Merge Ready Worktrees

Merge worktrees that are ready:
This:
  • Merges the branch to main
  • Removes the worktree
  • Deletes the branch

3. Clean Up Merged Worktrees

Remove any remaining merged worktrees:
This removes worktrees that were merged elsewhere (like through PRs).

4. Continue Working

Focus on in-progress worktrees:
Output:

Examples

Merge Single Worktree

Clean After PR Merges

After merging PRs on GitHub:
This removes local worktrees whose branches were merged remotely.

Emergency Cleanup

Remove all worktrees quickly:
This removes all worktrees including those with uncommitted changes.

Selective Merge

Comparison Table

When to Use Each Command

Use gwt merge when:

  • You’re ready to merge work to main
  • You want to merge and clean up in one step
  • You’re working with local branches (no PR)
  • You want the branch deleted automatically

Use gwt clean when:

  • Branches were merged via pull requests
  • You have multiple merged worktrees to remove
  • You want to preview before removing
  • You want to clean up old worktrees

Use gwt rm when:

  • You want to abandon work without merging
  • You need fine-grained control over removal
  • You want to remove specific worktrees
  • You want to search and select interactively

Next Steps