Skip to main content

Overview

After comparing attempts and choosing the best approach, it’s time to merge those changes into your main branch and clean up temporary worktrees.

The Merge Process


Merging Attempts

Via Web UI

1

Review Changes

Open task details → Click on completed attempt
2

Review Diff

Check all file changes carefully:
  • Files modified
  • Lines added/removed
  • Tests passing
3

Approve

Click “Approve & Merge” button
4

Confirm

Confirm merge in dialog:
5

Success

Task moves to “Done” column Worktree auto-cleaned

Via CLI


Merge Strategies

Fast-Forward Merge (Default)

Clean, linear history:
When to use: Single-developer, clean history preferred

Merge Commit

Preserves attempt branch history:
When to use: Multiple developers, want to preserve attempt context

Squash Merge

Combine all commits into one:
When to use: Clean up messy attempt history, single commit per feature

Pre-Merge Checks

Forge runs automatic checks before merging:

Test Suite

Custom Pre-Merge Hooks

Configure in .forge/hooks.yaml:
If any required check fails, merge is blocked:

Handling Merge Conflicts

Detecting Conflicts

Resolving Conflicts


Post-Merge Actions

Automatic Actions

After successful merge, Forge can:
.forge/hooks.yaml

Manual Post-Merge Steps

Common things you might do:

Cleanup

Automatic Cleanup (Default)

Forge automatically cleans up after merge:

Manual Cleanup

Sometimes you want to keep the worktree:

Cleanup Rejected Attempts


Worktree Management

List Worktrees

Remove Worktrees

Clean Orphaned Worktrees

Sometimes worktrees get orphaned (branch deleted but directory remains):
Forge runs this automatically, but you can trigger it manually if needed

Rolling Back Merges

Made a mistake? Undo the merge:

Immediate Rollback

Revert Merge

After pushing to remote:
This creates a new commit that undoes the merge, preserving history.

Merge Best Practices

Always Review First

Never merge without reviewing:

Keep Main Stable

Main branch should always work:
  • All tests must pass
  • No known bugs
  • Builds successfully
  • Deployed confidently

Meaningful Commit Messages

Clean Up Regularly

Don’t let worktrees accumulate:
Old worktrees waste disk space

Advanced: Partial Merges

Sometimes you want only specific files from an attempt:

Integration with CI/CD

Trigger Builds on Merge

.github/workflows/forge-merge.yml

Merge Gates

Require CI checks before merge:
.forge/config.json

Troubleshooting

Error: “Cannot merge: worktree is in detached HEAD state”Solution:
Error: “Cannot remove worktree: directory is locked”Solution:
Issue: Merge commit contains unintended filesSolution:
  • Check .gitignore is proper
  • Ensure node_modules/ not committed
  • Review files before merge:
  • Abort and fix:
Error: “Updates were rejected because the remote contains work that you do not have locally”Solution:

Cleanup Schedule

Recommended cleanup schedule:

Next Steps

Git Worktrees

Understand isolation strategy

Workflows

Complete development workflows

CI/CD Integration

Automate deployments

Troubleshooting

Fix common issues