Branch Management
💀 --------------------branches
The definitive reference for creating, managing, merging, and securing branches in the .git platform. Covers lifecycle states, protection rules, CLI operations, and enterprise workflows.
Overview
In .git, a branch is a lightweight pointer to a specific commit. Branches enable parallel development, feature isolation, release staging, and rapid hotfix deployment without disrupting the main codebase.
🌿 Isolation
Develop features, fix bugs, or experiment without affecting stable production code.
⚡ Parallelization
Multiple contributors work simultaneously. Merge conflicts are resolved deterministically.
🛡️ Governance
Enforce branch protection, required reviewers, automated checks, and retention policies.
Branch Types
| Type | Pattern | Purpose | Protection |
|---|---|---|---|
| Main | main / master | Production-ready code | Strict |
| Develop | develop | Integration for upcoming release | Moderate |
| Feature | feature/<name> | Isolated feature development | Auto |
| Release | release/<version> | Pre-production staging & QA | Moderate |
| Hotfix | hotfix/<issue> | Critical production patches | Moderate |
| Experiments | exp/<name> | R&D, proof-of-concepts | None |
💡 Tip
Branch naming conventions are enforced at the platform level. Attempting to create a branch outside allowed patterns will trigger a 403 BranchPatternViolation error.
Lifecycle & States
Every branch in .git transitions through a defined lifecycle. States are automatically updated based on activity, merge status, and retention policies.
| State | Trigger | Action |
|---|---|---|
active | Recent commits or open PR/MR | Normal operations allowed |
stale | 14+ days without activity | Flagged for review, CI paused |
merged | Successfully merged to target | Read-only, queued for cleanup |
abandoned | Manual close or timeout | Archived, metadata preserved |
CLI Reference
$ .git branch create feature/user-profile
✓ Created branch 'feature/user-profile' from 'develop'
$ .git branch switch feature/user-profile
✓ Switched to 'feature/user-profile'
Flags: --from <ref>, --template <file>, --protect
$ .git branch sync --all --remote origin
✓ Fetched 12 refs, pruned 4 stale branches
⚠ 3 branches require rebasing due to fast-forward divergence
Flags: --dry-run, --prune, --rebase, --strategy <fast-forward|squash|merge>
$ .git branch merge feature/auth --into main --squash
✓ Squash merged into 'main' [3 commits]
$ .git branch delete feature/auth --remote
✓ Deleted remote branch 'refs/heads/feature/auth'
Flags: --strategy <type>, --no-ff, --force, --remote
Naming Conventions
.git enforces semantic branch naming to improve traceability, automation, and audit compliance.
feature/<ticket>-<short-desc>→ New capabilitiesfix/<ticket>-<short-desc>→ Bug resolutionsrelease/v<x.y.z>→ Version staginghotfix/<issue>-<short-desc>→ Critical patcheschore/<scope>→ Dependencies, CI, configs
⚠️ Restriction
Branch names cannot contain spaces, special characters beyond - . /, or exceed 45 characters. Violations are rejected at the API layer.
Protection Rules
Branch protection prevents accidental degradation of critical code paths. Rules are evaluated in real-time before merges or force-pushes.
🔒 Strict (main/master)
- Require ≥2 approvals
- Block force pushes
- Require passing CI/CD
- Squash/merge only
- Linear history enforced
🔐 Moderate (develop/release)
- Require ≥1 approval
- Allow merge commits
- Require status checks
- Branch auto-prune after merge
Auto-Cleanup & Retention
To maintain repository hygiene, .git automatically manages merged and abandoned branches.
{
"cleanup_policy": {
"merged_retention_days": 3,
"stale_retention_days": 30,
"archive_metadata": true,
"notify_owners": true,
"allowed_patterns": ["main", "develop", "release/*", "hotfix/*"]
}
}
Configure retention via the Platform Dashboard or .git/config/branch-lifecycle.yaml. Overrides require admin:branches scope.
FAQ
Can I recover a deleted branch?
Yes. All branches are archived for 90 days by default. Use .git branch recover <ref> or restore via the Trash section in the dashboard. Enterprise plans support 365-day retention.
How does .git handle merge conflicts?
Conflicts are detected pre-merge via the .git diff-resolver. The platform offers 3-way diff UI, automatic safe-merge suggestions, and forced resolution workflows for CI pipelines.
Can I protect personal/experimental branches?
Yes. Run .git branch protect <name> --level personal to enable approval gates, CI requirements, and push restrictions without affecting team defaults.
Troubleshooting
| Error | Code | Cause | Resolution |
|---|---|---|---|
| Branch creation failed | 400 BadRefFormat | Invalid characters or length >45 | Rename to comply with conventions |
| Merge rejected | 409 Conflict | Unresolved divergence or failing checks | Rebase or resolve conflicts first |
| Force push blocked | 403 ProtectionViolation | Branch has strict protection enabled | Use merge/squash or temporarily disable rule |
| Remote sync timeout | 408 FetchTimeout | Large repo or network latency | Use --shallow or optimize pack files |