| name | branch-discipline |
| description | Use before any code changes - hard gate ensuring work never happens on main branch, with proper feature branch creation from correct base |
Branch Discipline
Overview
Never work on main. Create feature branches for all work.
Core principle: The main branch is sacred. All work happens in feature branches.
This is a HARD GATE. Do not proceed with code changes if on main.
The Gate
┌─────────────────────────────────────┐
│ CODE CHANGE NEEDED │
└─────────────────┬───────────────────┘
│
▼
┌─────────────────┐
│ Current branch? │
└────────┬────────┘
│
┌─────────┴─────────┐
│ │
main feature/*
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ STOP │ │ PROCEED │
│ Create │ │ with │
│ branch │ │ work │
└─────────┘ └─────────┘
Check Current Branch
git branch --show-current
Branch Naming Convention
Format
[type]/issue-[number]-[short-description]
Types
| Type | Use For |
|---|
feature | New functionality |
fix | Bug fixes |
chore | Maintenance, dependencies |
docs | Documentation only |
refactor | Code restructuring |
test | Test additions/fixes |
Examples
feature/issue-123-user-authentication
fix/issue-456-login-redirect-loop
chore/issue-789-update-dependencies
docs/issue-101-api-documentation
refactor/issue-202-extract-validation
test/issue-303-add-integration-tests
Creating a Feature Branch
From Main (Default)
git checkout main
git pull origin main
git checkout -b feature/issue-[NUMBER]-[description]
git push -u origin feature/issue-[NUMBER]-[description]
From Existing Feature Branch
When building on in-progress work:
git checkout feature/issue-100-base-feature
git pull origin feature/issue-100-base-feature
git checkout -b feature/issue-101-dependent-feature
Document the dependency in the issue.
Branch Lifecycle
Create → Work → Push → PR → Merge → Delete
After Merge
git checkout main
git pull origin main
git branch -d feature/issue-123-completed-feature
git push origin --delete feature/issue-123-completed-feature
Handling Stale Branches
If main has moved ahead:
git checkout feature/issue-123-my-feature
git fetch origin
git rebase origin/main
git checkout feature/issue-123-my-feature
git fetch origin
git merge origin/main
Protected Branches
Main should be protected. Never:
- Push directly to main
- Force push to main
- Delete main
If you accidentally commit to main:
git branch feature/issue-123-accidental-main
git reset --hard origin/main
Multiple Issues, Same Branch?
Generally NO. Each issue gets its own branch.
Exception: Tightly coupled sub-issues from issue-decomposition MAY share a branch if:
- They are sequential dependencies
- They will be merged together
- They are part of the same PR
Document this in the issues if doing so.
Verification
Before making any code change:
BRANCH=$(git branch --show-current)
if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then
echo "ERROR: On protected branch. Create feature branch first."
exit 1
fi
if ! echo "$BRANCH" | grep -qE '^(feature|fix|chore|docs|refactor|test)/issue-[0-9]+-'; then
echo "WARNING: Branch name doesn't follow convention"
fi
Common Mistakes
| Mistake | Prevention |
|---|
| Committing to main | Check branch before every commit |
| Pushing to main | Branch protection rules |
| Wrong base branch | Verify before creating branch |
| Outdated branch | Rebase/merge before PR |
| Branch name typos | Use consistent naming |
Checklist
Before writing any code:
Integration
This skill is called by:
issue-driven-development - Step 6
This skill enables:
- Clean separation of work
- Easy PR creation
- Safe experimentation