Skip to content

feat(migrate): make orphan branch default for bd migrate sync#1148

Closed
peterkc wants to merge 1 commit intosteveyegge:mainfrom
peterkc:feature/orphan-branch
Closed

feat(migrate): make orphan branch default for bd migrate sync#1148
peterkc wants to merge 1 commit intosteveyegge:mainfrom
peterkc:feature/orphan-branch

Conversation

@peterkc
Copy link
Contributor

@peterkc peterkc commented Jan 17, 2026

Summary

Make orphan branches the default for bd migrate sync and add --orphan flag for migrating existing branches.

Key behavior:

  • New branches: Created as orphan by default (no flag needed)
  • Existing branches: Used as-is (backward compatible)
  • Migration: Use --orphan to convert existing branch to orphan

Motivation: As suggested in #1125's Alternative section and #1004, orphan branches provide:

  • Clean "data sync channel" mental model
  • No accidental merge risk (git warns loudly)
  • Smaller repository footprint (no stale source code)

Changes

  • New sync branches are created as orphan by default
  • --orphan flag migrates existing branches (delete + recreate as orphan)
  • Safety check prevents data loss when --orphan would delete unpushed commits
  • Handles existing worktrees gracefully (removes before branch deletion)
  • Uses git commit-tree approach to avoid working directory conflicts
  • Existing branches without --orphan are preserved as-is
  • Add comprehensive tests for all scenarios
  • Add documentation to CLI_REFERENCE.md

Branch Creation Flow

bd migrate sync beads-sync
         |
         v
  ensureDirectMode()
         |
         v
  Branch exists locally/remotely?
        / \
      Yes   No
       |     |
       v     v
  --orphan?  Create orphan (default)
    / \
  Yes   No
   |     |
   v     v
  Has    Use existing
  unpushed?  as-is
    / \
  Yes   No
   |     |
   v     v
  Error  Remove worktree (if exists)
  (or    Delete + recreate orphan
  --force)

Behavior Matrix

Scenario --orphan Result
Branch doesn't exist N/A Create orphan (default)
Branch exists locally No Use as-is (backward compatible)
Branch exists locally Yes Migrate: delete + recreate as orphan
Branch exists + unpushed Yes Error (use --force to override)
Branch exists + worktree Yes Remove worktree first, then migrate
Remote only No Fetch from remote
Remote only Yes Create local orphan (ignore remote)

Backward Compatibility

Existing users with non-orphan sync branches are NOT affected:

  1. branchExistsLocal() detects the existing branch
  2. Without --orphan, code uses existing branch as-is
  3. Existing sync workflow continues unchanged

To migrate: bd migrate sync <branch> --orphan

Related Issues

Test Plan

  • TestMigrateSyncOrphan - Verifies orphan has no merge-base with main
  • TestMigrateSyncOrphanWorktree - Verifies worktree works with orphan branches
  • TestMigrateSyncExistingBranchPreserved - Verifies existing branches used as-is
  • TestMigrateSyncOrphanMigration - Verifies --orphan migrates existing branch
  • E2E: Migrated ACF repo from non-orphan to orphan with --orphan --force
  • All existing migrate sync tests pass

@peterkc peterkc changed the title feat(migrate): add --orphan flag to bd migrate sync feat(migrate): make orphan branch default for bd migrate sync Jan 17, 2026
@peterkc peterkc force-pushed the feature/orphan-branch branch 4 times, most recently from 87d02dc to e639a04 Compare January 17, 2026 18:57
@peterkc
Copy link
Contributor Author

peterkc commented Jan 17, 2026

CI Note

The lint and version consistency failures are pre-existing issues on main, not caused by this PR.

Lint failures (all in files not touched by this PR):

  • cmd/bd/hook.go - errcheck, unparam
  • cmd/bd/sync.go - gosec
  • internal/storage/dolt/bootstrap.go - gosec

Version mismatch:

  • MCP __init__.py has 0.47.2 instead of 0.48.0

This PR only modifies:

  • cmd/bd/migrate_sync.go
  • cmd/bd/migrate_sync_test.go
  • docs/CLI_REFERENCE.md

All tests for migrate_sync pass locally.

@peterkc peterkc marked this pull request as ready for review January 17, 2026 19:07
@peterkc peterkc marked this pull request as draft January 17, 2026 19:10
@peterkc peterkc force-pushed the feature/orphan-branch branch from e639a04 to 76198d5 Compare January 17, 2026 19:18
New sync branches are created as orphan by default - no shared history
with main, creating a clean "data sync channel" for beads.

Changes:
- New branches: Created as orphan via `git checkout --orphan`
- Existing branches: Preserved as-is for backward compatibility
- Migration: `--orphan` flag deletes and recreates existing branch
- Safety check: Warns if --orphan would lose unpushed commits

Why orphan branches:
- Clean mental model (data-only branch, no code)
- No accidental merge risk (git warns about unrelated histories)
- Smaller repository footprint

Addresses GH#1004 Phase 1 and GH#1125.
@peterkc peterkc force-pushed the feature/orphan-branch branch from 76198d5 to a96fbc9 Compare January 17, 2026 19:22
@peterkc peterkc marked this pull request as ready for review January 17, 2026 19:23
steveyegge added a commit that referenced this pull request Feb 5, 2026
Make orphan branches the default for `bd migrate sync` when creating
new branches, providing cleaner separation of sync data from main code.

Key changes:
- New branches created as orphan by default (no shared history)
- Existing branches used as-is (backward compatible)
- --orphan flag to migrate existing branches to orphan
- Safety checks for unpushed commits
- Cross-platform fix: use --stdin instead of /dev/null

Co-Authored-By: Peter Chanthamynavong <peterkc@users.noreply.github.com>
@steveyegge
Copy link
Owner

Merged manually to main with cross-platform fix (replaced /dev/null with --stdin for Windows compatibility). Thanks @peterkc!

@steveyegge steveyegge closed this Feb 5, 2026
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.

Feature: bd migrate sync --clean to create minimal orphan branch

2 participants