Git Workflow & Branching
Purpose
Clean git history is essential for debugging (git bisect), code review, and team collaboration. This skill standardizes branch naming, commit formatting, and merging to maintain a readable, revertible, and bisect-able history.
When to use
- Starting a new feature or bugfix ticket
- Reviewing PRs and merging code into mainline
- Hotfixing production environments
- Onboarding new team members
When NOT to use
- Dealing with complex merge conflicts (use git documentation)
- Repository history rewrites (different concern)
- CI/CD trigger configuration (separate skill)
Inputs required
- Git repository with
main branch
- Remote repository (GitHub, GitLab, Gitea)
- Team agreement on branch naming and commit conventions
Workflow
- Sync Main: ALWAYS fetch and pull latest from
main before creating branch
- Create Branch: Use convention
type/ticket-id-short-description (e.g., feat/PROJ-123-add-login)
- Commit Atomically: Commit in small logical chunks. MUST use Conventional Commits format
- Keep Branch Synced: Rebase against
main frequently to avoid merge conflicts
- Push Regularly: Push to remote regularly (enables collaboration, backup)
- Rebase Before PR: Interactive rebase to clean up WIP commits before opening PR
- Squash Merge: Merge PR using squash-merge to keep main history clean
- Delete Branch: Delete feature branch after merging (cleanup)
Rules
- MUST NEVER push directly to
main (always use PRs)
- MUST use Conventional Commits:
feat:, fix:, docs:, chore:, refactor:, test:
- MUST rebase before opening PR (no merge commits from main)
- MUST delete feature branches after merging
- MUST NOT commit with messages like "wip", "fixed typo", "trying again"
- MUST resolve conflicts locally before pushing
- MUST NOT force-push to shared branches
- MUST keep feature branches <5 days old before merging
Anti-patterns
- WIP Commits: Pushing commits like "wip", "fixed typo", "let me try again" to main
- Long-lived Branches: Keeping branches active for weeks without syncing with main
- Merge Commits: Allowing merge commits from main to pollute history (use rebase)
- Squashing Too Early: Squashing before PR review (makes feedback hard to track)
- Force Pushing to Shared:
git push -f on branches other developers are using
- Vague Messages: "Update stuff", "fix bug" (impossible to bisect later)
Failure conditions
- Direct push to
main detected
- Merge conflicts exist when opening PR
- Broken tests or CI failures on main
- WIP commits in main history
- Feature branches never deleted after merge
Validation checklist
Output format
- Branch naming:
type/ticket-id-short-desc (e.g., feat/AUTH-42-oauth-integration)
- Commit format:
type(scope): description\n\nbody\n\nfooter
- History: Linear commits on main (no merge commits)
- Merge strategy: Squash-merge to single conventional commit
Security considerations
- NEVER commit secrets (use
.gitignore, environment variables)
- Code review MUST happen before main (enforce via PR requirements)
- Force-push MUST be disabled on main branch
- Branch protection rules MUST require passing CI
Agent execution notes
- Agent MAY: Create branches, make commits, rebase branches, resolve conflicts, open PRs
- Agent MUST NEVER: Push directly to main, create WIP commits, force-push shared branches
- Agent MUST ASK: Before force-pushing, before deleting branches, before modifying main history
- Agent MUST VALIDATE: Branch follows naming convention, commits are conventional, CI passes
Example
❌ Anti-pattern (WIP commits, vague messages, no rebasing):
git checkout main
# Forgot to pull - out of sync
git checkout -b feature-branch
git commit -m "wip"
git commit -m "fixed typo"
git commit -m "let me try again"
git commit -m "update stuff"
git push origin feature-branch
# Merge directly to main without PR
✅ Correct pattern (Atomic commits, conventional, rebased, squashed):
git fetch origin
git checkout -b feat/PROJ-123-add-oauth
# Make atomic commits with conventional format
git commit -m "feat(auth): add oauth service initialization"
git commit -m "feat(auth): implement oauth callback handler"
git commit -m "test(auth): add oauth flow tests"
git push origin feat/PROJ-123-add-oauth
# Before PR: rebase and squash if needed
git fetch origin
git rebase origin/main
# Squash merge via PR (git will handle this)
# After merge:
git checkout main
git pull origin main
git branch -d feat/PROJ-123-add-oauth
git push origin --delete feat/PROJ-123-add-oauth
Source: KraitDev/skiLL.Md — distributed by TomeVault.
1---2name: git-workflow-branching3description: When creating, updating, and merging code in a collaborative version control environment. Use when this capability is needed.4---56# Git Workflow & Branching78## Purpose9Clean git history is essential for debugging (`git bisect`), code review, and team collaboration. This skill standardizes branch naming, commit formatting, and merging to maintain a readable, revertible, and bisect-able history.1011## When to use12- Starting a new feature or bugfix ticket13- Reviewing PRs and merging code into mainline14- Hotfixing production environments15- Onboarding new team members1617## When NOT to use18- Dealing with complex merge conflicts (use git documentation)19- Repository history rewrites (different concern)20- CI/CD trigger configuration (separate skill)2122## Inputs required23- Git repository with `main` branch24- Remote repository (GitHub, GitLab, Gitea)25- Team agreement on branch naming and commit conventions2627## Workflow281. **Sync Main**: ALWAYS fetch and pull latest from `main` before creating branch292. **Create Branch**: Use convention `type/ticket-id-short-description` (e.g., `feat/PROJ-123-add-login`)303. **Commit Atomically**: Commit in small logical chunks. MUST use Conventional Commits format314. **Keep Branch Synced**: Rebase against `main` frequently to avoid merge conflicts325. **Push Regularly**: Push to remote regularly (enables collaboration, backup)336. **Rebase Before PR**: Interactive rebase to clean up WIP commits before opening PR347. **Squash Merge**: Merge PR using squash-merge to keep main history clean358. **Delete Branch**: Delete feature branch after merging (cleanup)3637## Rules38- MUST NEVER push directly to `main` (always use PRs)39- MUST use Conventional Commits: `feat:`, `fix:`, `docs:`, `chore:`, `refactor:`, `test:`40- MUST rebase before opening PR (no merge commits from main)41- MUST delete feature branches after merging42- MUST NOT commit with messages like "wip", "fixed typo", "trying again"43- MUST resolve conflicts locally before pushing44- MUST NOT force-push to shared branches45- MUST keep feature branches <5 days old before merging4647## Anti-patterns48- **WIP Commits**: Pushing commits like "wip", "fixed typo", "let me try again" to main49- **Long-lived Branches**: Keeping branches active for weeks without syncing with main50- **Merge Commits**: Allowing merge commits from main to pollute history (use rebase)51- **Squashing Too Early**: Squashing before PR review (makes feedback hard to track)52- **Force Pushing to Shared**: `git push -f` on branches other developers are using53- **Vague Messages**: "Update stuff", "fix bug" (impossible to bisect later)5455## Failure conditions56- Direct push to `main` detected57- Merge conflicts exist when opening PR58- Broken tests or CI failures on main59- WIP commits in main history60- Feature branches never deleted after merge6162## Validation checklist63- [ ] Branch created from latest main64- [ ] Branch name follows `type/ticket-id-description` format65- [ ] All commits use Conventional Commits format66- [ ] No "wip", "fixed typo", or vague commit messages67- [ ] Commits are atomic (each solves one thing)68- [ ] Rebase completed, no merge commits from main69- [ ] All conflicts resolved locally70- [ ] CI passes before PR merge71- [ ] PR description links ticket72- [ ] Branch deleted after merging7374## Output format75- **Branch naming**: `type/ticket-id-short-desc` (e.g., `feat/AUTH-42-oauth-integration`)76- **Commit format**: `type(scope): description\n\nbody\n\nfooter`77- **History**: Linear commits on main (no merge commits)78- **Merge strategy**: Squash-merge to single conventional commit7980## Security considerations81- NEVER commit secrets (use `.gitignore`, environment variables)82- Code review MUST happen before main (enforce via PR requirements)83- Force-push MUST be disabled on main branch84- Branch protection rules MUST require passing CI8586## Agent execution notes87- Agent MAY: Create branches, make commits, rebase branches, resolve conflicts, open PRs88- Agent MUST NEVER: Push directly to main, create WIP commits, force-push shared branches89- Agent MUST ASK: Before force-pushing, before deleting branches, before modifying main history90- Agent MUST VALIDATE: Branch follows naming convention, commits are conventional, CI passes9192## Example9394**❌ Anti-pattern (WIP commits, vague messages, no rebasing):**95```bash96git checkout main97# Forgot to pull - out of sync98git checkout -b feature-branch99git commit -m "wip"100git commit -m "fixed typo"101git commit -m "let me try again"102git commit -m "update stuff"103git push origin feature-branch104# Merge directly to main without PR105```106107**✅ Correct pattern (Atomic commits, conventional, rebased, squashed):**108```bash109git fetch origin110git checkout -b feat/PROJ-123-add-oauth111112# Make atomic commits with conventional format113git commit -m "feat(auth): add oauth service initialization"114git commit -m "feat(auth): implement oauth callback handler"115git commit -m "test(auth): add oauth flow tests"116117git push origin feat/PROJ-123-add-oauth118119# Before PR: rebase and squash if needed120git fetch origin121git rebase origin/main122123# Squash merge via PR (git will handle this)124# After merge:125git checkout main126git pull origin main127git branch -d feat/PROJ-123-add-oauth128git push origin --delete feat/PROJ-123-add-oauth129```130131---132> Source: [KraitDev/skiLL.Md](https://github.com/KraitDev/skiLL.Md) — distributed by [TomeVault](https://tomevault.io).133<!-- tomevault:4.0:skill_md:2026-06-16 -->