Branch Management¶
Cub provides commands for creating and managing git branches that are associated with epics. This enables organized, trackable development where branches map to logical units of work.
The cub branch Command¶
Create a new branch and bind it to an epic:
Basic Usage¶
# Create new branch for an epic
cub branch cub-vd6
# Output:
# Created branch: feature/cub-vd6
# Bound to epic: cub-vd6
This command:
- Creates a new git branch (if not already on one)
- Records the binding in
.beads/branches.yaml - Stores metadata for later PR creation
Options¶
| Option | Description |
|---|---|
--name <branch> | Custom branch name (default: feature/<epic-id>) |
--bind-only | Bind current branch without creating new one |
--base <branch> | Base branch to create from (default: current) |
Examples¶
# Create branch with custom name
cub branch cub-vd6 --name feature/v19-git-workflow
# Bind existing branch to epic
git checkout -b my-feature
cub branch cub-vd6 --bind-only
# Create from specific base branch
cub branch cub-vd6 --base develop
Branch Naming Convention¶
Cub uses a consistent naming convention for branches:
Session Branches (Auto-Branch Hook)¶
Created automatically when using the auto-branch hook:
Examples: - cub/porcupine/20260111-114543 - cub/narwhal/20260111-120000
Epic Branches (cub branch Command)¶
Created when binding a branch to an epic:
Examples: - feature/cub-vd6 - feature/cub-abc123
You can customize the name with --name:
Epic-Branch Bindings¶
Bindings are stored in .beads/branches.yaml:
bindings:
- epic_id: cub-vd6
branch: feature/cub-vd6
base_branch: main
created_at: 2026-01-11T11:45:43Z
status: active
pr_number: null
Binding Fields¶
| Field | Description |
|---|---|
epic_id | The epic this branch implements |
branch | Git branch name |
base_branch | Target branch for eventual PR |
created_at | When the binding was created |
status | active, merged, or closed |
pr_number | Associated PR number (if created) |
Managing Branches¶
List Bindings¶
View all branch-epic bindings:
Output:
Epic Branch Base Status PR
cub-vd6 feature/cub-vd6 main active -
cub-abc feature/cub-abc main merged #42
cub-xyz feature/cub-xyz main active #45
Filter by Status¶
# Only active branches
cub branches --status active
# Only merged branches
cub branches --status merged
JSON Output¶
For scripting:
{
"bindings": [
{
"epic_id": "cub-vd6",
"branch": "feature/cub-vd6",
"base_branch": "main",
"status": "active"
}
]
}
Remove Binding¶
Unbind a branch from its epic:
This removes the binding but does not delete the branch.
Cleanup Merged Branches¶
Remove branches that have been merged:
This: 1. Checks which bound branches are merged into their base 2. Deletes the merged branches 3. Updates binding status to merged
Sync Status¶
Update binding status from git state:
This checks if branches have been merged and updates the binding records accordingly.
Workflow Integration¶
With cub run¶
When running tasks for a specific epic, cub uses the bound branch:
With cub pr¶
Pull request creation uses binding information:
The binding provides: - Source branch (from binding) - Target branch (from base_branch) - PR title (from epic title) - PR body (from completed tasks)
With Checkpoints¶
Branches can have associated checkpoints (review gates):
# Create a checkpoint for the branch
bd create "Review: feature complete" --type gate --parent cub-vd6
# List checkpoints
cub checkpoints --epic cub-vd6
# Approve checkpoint to unblock further work
cub checkpoints approve <checkpoint-id>
Best Practices¶
1. One Epic per Branch¶
Each epic should have exactly one branch. This keeps the mapping clear:
# Good: Each epic has its own branch
cub branch cub-001
cub branch cub-002
# Avoid: Multiple epics on one branch
2. Use Descriptive Names for Large Features¶
For significant features, use custom branch names:
3. Clean Up After Merging¶
Regularly clean up merged branches:
4. Sync Before Starting Work¶
Ensure bindings are current:
Troubleshooting¶
Branch Already Exists¶
Solution: Bind to existing branch instead:
Epic Already Bound¶
Solution: Check existing binding:
If you need to rebind, first unbind:
Binding Not Found¶
Solution: Create the binding:
Or if the branch exists: