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

TypePatternPurposeProtection
Mainmain / masterProduction-ready codeStrict
DevelopdevelopIntegration for upcoming releaseModerate
Featurefeature/<name>Isolated feature developmentAuto
Releaserelease/<version>Pre-production staging & QAModerate
Hotfixhotfix/<issue>Critical production patchesModerate
Experimentsexp/<name>R&D, proof-of-conceptsNone

💡 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.

feature/auth
develop
main
StateTriggerAction
activeRecent commits or open PR/MRNormal operations allowed
stale14+ days without activityFlagged for review, CI paused
mergedSuccessfully merged to targetRead-only, queued for cleanup
abandonedManual close or timeoutArchived, 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 capabilities
  • fix/<ticket>-<short-desc> → Bug resolutions
  • release/v<x.y.z> → Version staging
  • hotfix/<issue>-<short-desc> → Critical patches
  • chore/<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

ErrorCodeCauseResolution
Branch creation failed400 BadRefFormatInvalid characters or length >45Rename to comply with conventions
Merge rejected409 ConflictUnresolved divergence or failing checksRebase or resolve conflicts first
Force push blocked403 ProtectionViolationBranch has strict protection enabledUse merge/squash or temporarily disable rule
Remote sync timeout408 FetchTimeoutLarge repo or network latencyUse --shallow or optimize pack files