Git Branch Management Skill
This skill guides AI agents and human contributors on how to create, name, structure, and navigate Git branches in the GitHub Backup Automation System repository.
1. Core Branching Principles
- Mandatory Local Branch Creation: Prior to modifying any code, configuration, or documentation files for ANY task, you MUST ALWAYS create and switch to a dedicated local branch (
git switch -c <github-username>/<parent-branch>/<feature>). Never develop or commit directly on main or dev.
- Branch-First Development: All changes (features, fixes, refactoring, tests, docs) are developed directly on Git branches created from
main.
- Strict No-Worktree Rule: AI agents and contributors must NOT create or use Git worktrees for standard development tasks. All work occurs in the primary repository clone via branch switching (
git switch -c).
- Structured Hierarchical Naming: Branch names follow the standard format
<github-username>/<parent-branch>/<feature>.
- All Pull Requests Target
main: main is the sole production integration branch. Never open PRs against dev or temporary feature branches.
- Agent Safety Boundaries:
- Agents may create or switch between local branches directly.
- STRICT RULE: Agents MUST NOT push branches to a remote repository automatically. Pushing and opening PRs is permitted ONLY upon explicit human request.
- STRICT RULE: Agents MUST NEVER force-push (
git push --force) or delete remote branches.
2. Branch Naming Convention
All development branches MUST follow the standard structure:
<github-username>/<parent-branch>/<feature>
Components Breakdown
<github-username>: GitHub username of the author (e.g. MishraShardendu22).
<parent-branch>: Target base branch name (typically main).
<feature>: Concise, kebab-case description of the feature or fix (e.g. database-auto-sync, precommit-workflow, branch-first-migration).
Rules
- Lowercase: All characters lowercase.
- Kebab-Case: Hyphen-separated words for the feature portion.
- Concise: 2–4 descriptive words.
- No Timestamps/Hashes: Avoid timestamps or random suffixes unless required for uniqueness.
3. Canonical Branch Workflow Runbook
For Human Contributors
# 1. Update main branch
git checkout main
git pull origin main
# 2. Create and switch to new branch
git switch -c MishraShardendu22/main/my-feature
# 3. Develop, validate, and commit
make pre-commit
git add .
git commit -s -S -m "feat(worker): add new capability"
# 4. Push and open PR
git push -u origin MishraShardendu22/main/my-feature
gh pr create --base main --head MishraShardendu22/main/my-feature --title "feat(worker): add new capability" --body "..."
For AI Agents
- Inspect repository and branch status (do NOT spawn worktrees):
git status
git branch -a
- Switch to
main and pull latest changes:git switch main
git pull origin main
- Create local branch:
git switch -c <github-username>/<parent-branch>/<feature>
- Develop directly on that branch, run
make pre-commit, and commit locally with -s and -S.
- When explicitly requested by the user, push to remote and open a PR targeting
main.
4. Single Open PR Mandate & Preventing Merge Conflicts
To ensure continuous delivery without merge conflict deadlock:
- Mandatory Pre-Branch Check: Always run
gh pr list --state open before creating a new branch.
- Consolidate into Existing Open PR: If an open PR already exists targeting
main, DO NOT create a new branch or open a secondary PR. Check out the existing PR's branch (git checkout <open-branch>), implement all requested changes there, and push to that same branch.
- Open New PR Only on Clean State: Create a new feature branch and open a new PR ONLY when zero open PRs exist.
- Rebasing: If
main is updated while a PR is open, rebase your branch on origin/main (git fetch origin && git rebase origin/main), re-verify with make pre-commit, and push with --force-with-lease.
5. Merging & Local Branch Cleanup
- Once a Pull Request is merged into
main on GitHub and upon explicit human user instruction, perform safe branch cleanup and repository garbage collection:make git-clean
Or manual sequence:git switch main
git pull origin main
git fetch --prune origin
git branch | grep -v "^\* main$" | grep -v "^ main$" | xargs -r git branch -D
git reflog expire --expire=now --all
git gc --prune=now --aggressive
- Explicit Instruction Only: AI agents must only execute branch cleanup when explicitly asked by the user after PR merge.
- See
.agents/skills/git-post-merge-cleanup/SKILL.md.
1---2name: git-branch-management3description: Rules and procedures for creating, naming, structuring, and navigating Git branches in the repository for both human contributors and AI agents.4---56# Git Branch Management Skill78This skill guides AI agents and human contributors on how to create, name, structure, and navigate Git branches in the **GitHub Backup Automation System** repository.910---1112## 1. Core Branching Principles13141. **Mandatory Local Branch Creation**: Prior to modifying any code, configuration, or documentation files for ANY task, you MUST ALWAYS create and switch to a dedicated local branch (`git switch -c <github-username>/<parent-branch>/<feature>`). Never develop or commit directly on `main` or `dev`.152. **Branch-First Development**: All changes (features, fixes, refactoring, tests, docs) are developed directly on Git branches created from `main`.163. **Strict No-Worktree Rule**: AI agents and contributors must **NOT** create or use Git worktrees for standard development tasks. All work occurs in the primary repository clone via branch switching (`git switch -c`).174. **Structured Hierarchical Naming**: Branch names follow the standard format `<github-username>/<parent-branch>/<feature>`.185. **All Pull Requests Target `main`**: `main` is the sole production integration branch. Never open PRs against `dev` or temporary feature branches.196. **Agent Safety Boundaries**:20 * Agents may create or switch between local branches directly.21 * **STRICT RULE**: Agents MUST NOT push branches to a remote repository automatically. Pushing and opening PRs is permitted ONLY upon explicit human request.22 * **STRICT RULE**: Agents MUST NEVER force-push (`git push --force`) or delete remote branches.2324---2526## 2. Branch Naming Convention2728All development branches MUST follow the standard structure:2930```text31<github-username>/<parent-branch>/<feature>32```3334### Components Breakdown35* `<github-username>`: GitHub username of the author (e.g. `MishraShardendu22`).36* `<parent-branch>`: Target base branch name (typically `main`).37* `<feature>`: Concise, kebab-case description of the feature or fix (e.g. `database-auto-sync`, `precommit-workflow`, `branch-first-migration`).3839### Rules40* **Lowercase**: All characters lowercase.41* **Kebab-Case**: Hyphen-separated words for the feature portion.42* **Concise**: 2–4 descriptive words.43* **No Timestamps/Hashes**: Avoid timestamps or random suffixes unless required for uniqueness.4445---4647## 3. Canonical Branch Workflow Runbook4849### For Human Contributors50```bash51# 1. Update main branch52git checkout main53git pull origin main5455# 2. Create and switch to new branch56git switch -c MishraShardendu22/main/my-feature5758# 3. Develop, validate, and commit59make pre-commit60git add .61git commit -s -S -m "feat(worker): add new capability"6263# 4. Push and open PR64git push -u origin MishraShardendu22/main/my-feature65gh pr create --base main --head MishraShardendu22/main/my-feature --title "feat(worker): add new capability" --body "..."66```6768### For AI Agents691. Inspect repository and branch status (do NOT spawn worktrees):70 ```bash71 git status72 git branch -a73 ```742. Switch to `main` and pull latest changes:75 ```bash76 git switch main77 git pull origin main78 ```793. Create local branch:80 ```bash81 git switch -c <github-username>/<parent-branch>/<feature>82 ```834. Develop directly on that branch, run `make pre-commit`, and commit locally with `-s` and `-S`.845. When explicitly requested by the user, push to remote and open a PR targeting `main`.8586---8788## 4. Single Open PR Mandate & Preventing Merge Conflicts8990To ensure continuous delivery without merge conflict deadlock:91* **Mandatory Pre-Branch Check**: Always run `gh pr list --state open` before creating a new branch.92* **Consolidate into Existing Open PR**: If an open PR already exists targeting `main`, DO NOT create a new branch or open a secondary PR. Check out the existing PR's branch (`git checkout <open-branch>`), implement all requested changes there, and push to that same branch.93* **Open New PR Only on Clean State**: Create a new feature branch and open a new PR ONLY when zero open PRs exist.94* **Rebasing**: If `main` is updated while a PR is open, rebase your branch on `origin/main` (`git fetch origin && git rebase origin/main`), re-verify with `make pre-commit`, and push with `--force-with-lease`.9596---9798## 5. Merging & Local Branch Cleanup991001. Once a Pull Request is merged into `main` on GitHub and upon explicit human user instruction, perform safe branch cleanup and repository garbage collection:101 ```bash102 make git-clean103 ```104 Or manual sequence:105 ```bash106 git switch main107 git pull origin main108 git fetch --prune origin109 git branch | grep -v "^\* main$" | grep -v "^ main$" | xargs -r git branch -D110 git reflog expire --expire=now --all111 git gc --prune=now --aggressive112 ```1132. **Explicit Instruction Only**: AI agents must only execute branch cleanup when explicitly asked by the user after PR merge.1143. See [`.agents/skills/git-post-merge-cleanup/SKILL.md`](../git-post-merge-cleanup/SKILL.md).115