Skip to content

feat(git): auto-create feature branch when committing on mainline - #12

Merged
cblecker merged 1 commit into
mainfrom
feat/auto-branch-on-mainline
Feb 11, 2026
Merged

feat(git): auto-create feature branch when committing on mainline#12
cblecker merged 1 commit into
mainfrom
feat/auto-branch-on-mainline

Conversation

@cblecker

@cblecker cblecker commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Summary

This PR implements automatic feature branch creation when using the git:commit skill while on the mainline branch, replacing the previous soft "recommended" approach that often prompted for user confirmation.

Changes

  • git/skills/commit/SKILL.md: Updated mainline branch protection to:

    • Check for explicit opt-out language in user prompt or CLAUDE.md
    • Auto-create feature branch by default (no asking)
    • Use directive language: "Creating a feature branch" instead of "recommended"
  • git/skills/pr/SKILL.md: Reordered pre-flight checks to:

    • Check uncommitted changes first
    • Then verify branch (since commit skill auto-creates branches)

Testing

  • ✅ Markdown linting passed for both modified files
  • Manual testing required:
    • Invoke git:commit while on mainline → should auto-create branch without asking
    • Invoke git:commit with "commit directly to main" → should skip branch creation

Related

Implements the plan from previous session to make auto-branching the default behavior with explicit opt-out support.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Enhancements

    • Commit workflow now conditionally allows direct mainline commits when user prompt or permission allows; otherwise auto-creates and switches to a feature branch with clearer messaging.
    • PR flow adds explicit pre-flight checks for uncommitted changes and re-evaluates branch state after commits.
    • Improved fork vs direct-repo handling so pushes and PR targets behave correctly for forks and upstream repos.
  • Bug Fixes / UX

    • If user declines committing uncommitted changes, the process stops and advises to commit or stash before continuing.

@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: automatic feature-branch creation when committing on mainline, which is the primary objective of this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/auto-branch-on-mainline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
git/skills/commit/SKILL.md (1)

10-10: ⚠️ Potential issue | 🟡 Minor

Update Quick Reference to reflect conditional branching logic.

Line 10 states "Check if on mainline (if yes, create branch first)" but the actual workflow (lines 47-49) now includes conditional logic to check for opt-out language before deciding whether to create a branch.

📝 Proposed fix to align Quick Reference with workflow
-1. Check if on mainline (if yes, create branch first)
+1. Check if on mainline (if yes, create branch unless explicitly allowed)
🤖 Fix all issues with AI agents
In `@git/skills/commit/SKILL.md`:
- Line 47: Update the mainline opt-out detection to read the project CLAUDE.md
"## Git Workflow" section (consistent with the pre-commit verification logic)
and only treat mainline as allowed if that section contains explicit phrases
such as "commit to main", "mainline", or "allow direct commits"; if the section
is missing or the wording is ambiguous, fall back to creating a feature branch.
Modify the existing "mainline opt-out detection" logic so it parses the "## Git
Workflow" heading, searches only within that section for the keywords above, and
defaults to branch creation when unclear, keeping the pre-commit verification
behavior as the authoritative source.

In `@git/skills/pr/SKILL.md`:
- Around line 31-39: The uncommitted-changes branch is missing handling for when
the user declines to commit: after prompting "You have uncommitted changes.
Would you like to commit them first?" if the user answers "no" you must
immediately check the current branch against the mainline and abort with an
error if it's the mainline; update the flow that invokes the commit skill (the
"commit" skill invocation block) to include an explicit "decline" branch which
queries the current branch name and raises an error suggesting creating a
feature branch (or instructs the user to commit later) when on mainline,
otherwise continue the PR process with an explicit warning about uncommitted
changes.
🧹 Nitpick comments (1)
git/skills/pr/SKILL.md (1)

39-39: Minor clarity: rephrase "changes to PR" for readability.

The phrase "with the changes to PR" at the end of line 39 could be clearer. Consider: "error and suggest creating a feature branch first for the changes you want to include in the PR."

Comment thread git/skills/commit/SKILL.md
Comment thread git/skills/pr/SKILL.md Outdated
Comment on lines +31 to +39
**If uncommitted changes exist:**

1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process

**Verify branch is not mainline:**

If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Incomplete conditional: handle user declining to commit.

The uncommitted changes flow (lines 31-35) asks if the user wants to commit, but doesn't specify what happens if the user says "no". If the user declines, the mainline check at line 39 won't trigger (since uncommitted changes still exist), allowing the PR flow to continue with uncommitted changes on the mainline branch.

Expected behavior: If the user declines to commit and is on the mainline branch with uncommitted changes, the skill should error out rather than proceeding.

📋 Proposed fix to handle the "no" case
 **If uncommitted changes exist:**
 
 1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
 2. If yes, invoke the `commit` skill using the Skill tool
 3. After commit succeeds, continue with PR process
+4. If no, stop and inform user they must commit or stash changes before creating a PR
 
 **Verify branch is not mainline:**
 
 If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
**If uncommitted changes exist:**
1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process
**Verify branch is not mainline:**
If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR.
**If uncommitted changes exist:**
1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process
4. If no, stop and inform user they must commit or stash changes before creating a PR
**Verify branch is not mainline:**
If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first with the changes to PR.
🤖 Prompt for AI Agents
In `@git/skills/pr/SKILL.md` around lines 31 - 39, The uncommitted-changes branch
is missing handling for when the user declines to commit: after prompting "You
have uncommitted changes. Would you like to commit them first?" if the user
answers "no" you must immediately check the current branch against the mainline
and abort with an error if it's the mainline; update the flow that invokes the
commit skill (the "commit" skill invocation block) to include an explicit
"decline" branch which queries the current branch name and raises an error
suggesting creating a feature branch (or instructs the user to commit later)
when on mainline, otherwise continue the PR process with an explicit warning
about uncommitted changes.

@cblecker
cblecker force-pushed the feat/auto-branch-on-mainline branch from b7558ab to 45adfb9 Compare February 11, 2026 03:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@git/skills/pr/SKILL.md`:
- Around line 31-40: After the doc's "yes → commit" flow, add an explicit step
to refresh git state and re-run the branch checks (the uncommitted-changes and
"not on mainline" prerequisite) after the `commit` skill finishes; specifically,
invoke the same branch-detection/validation logic used in the pre-commit path to
re-evaluate the current branch (to catch auto-branching or opts-out) and if the
branch equals the mainline branch halt PR creation and instruct the user to
create a feature branch before proceeding.

Comment thread git/skills/pr/SKILL.md Outdated
Comment on lines +31 to +40
**If uncommitted changes exist:**

1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process
4. If no, stop and inform user they must commit or stash changes before creating a PR

**Verify branch is not mainline:**

If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Re-check branch (and refresh git state) after commit skill runs.

After committing, the branch may have changed (auto-branching or an explicit mainline opt‑out). The flow currently skips the “not on mainline” prerequisite in the “yes → commit” path, which can let PR creation proceed from mainline. Re-run the git state checks and enforce the mainline rule after the commit completes.

🔧 Suggested doc tweak
 2. If yes, invoke the `commit` skill using the Skill tool
-3. After commit succeeds, continue with PR process
+3. After commit succeeds, re-fetch git state (current branch, uncommitted changes)
+4. If current branch equals mainline, stop and instruct creating a feature branch
+5. Continue with PR process
-4. If no, stop and inform user they must commit or stash changes before creating a PR
+6. If no, stop and inform user they must commit or stash changes before creating a PR

Based on learnings: “All skills should check prerequisites (uncommitted changes, base branch, not on mainline) before doing detection work.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
**If uncommitted changes exist:**
1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, continue with PR process
4. If no, stop and inform user they must commit or stash changes before creating a PR
**Verify branch is not mainline:**
If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR.
**If uncommitted changes exist:**
1. Ask user: "You have uncommitted changes. Would you like to commit them first?"
2. If yes, invoke the `commit` skill using the Skill tool
3. After commit succeeds, re-fetch git state (current branch, uncommitted changes)
4. If current branch equals mainline, stop and instruct creating a feature branch
5. Continue with PR process
6. If no, stop and inform user they must commit or stash changes before creating a PR
**Verify branch is not mainline:**
If there are no uncommitted changes, and the current branch equals mainline branch, error and suggest creating a feature branch first for the changes you want to include in the PR.
🤖 Prompt for AI Agents
In `@git/skills/pr/SKILL.md` around lines 31 - 40, After the doc's "yes → commit"
flow, add an explicit step to refresh git state and re-run the branch checks
(the uncommitted-changes and "not on mainline" prerequisite) after the `commit`
skill finishes; specifically, invoke the same branch-detection/validation logic
used in the pre-commit path to re-evaluate the current branch (to catch
auto-branching or opts-out) and if the branch equals the mainline branch halt PR
creation and instruct the user to create a feature branch before proceeding.

Update commit skill to automatically create a feature branch when user
is on mainline, instead of just recommending it. Skill now checks for
explicit opt-out language in user prompt or CLAUDE.md before auto-branching.

Update PR skill pre-flight check order to check uncommitted changes first,
since commit skill will handle branch creation automatically.

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
@cblecker
cblecker force-pushed the feat/auto-branch-on-mainline branch from 45adfb9 to 95e69a7 Compare February 11, 2026 03:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
git/skills/commit/SKILL.md (1)

47-57: ⚠️ Potential issue | 🟡 Minor

Avoid auto‑creating a branch when there are no changes to commit.

Right now the mainline check runs before verifying changes, so a feature branch is created even when the working tree is clean. Consider checking for changes first and exiting early if none exist.

Proposed doc tweak
-**If on mainline branch:**
-
-Check if the user's prompt or project CLAUDE.md explicitly allows committing directly to mainline (e.g., "commit to main", "no feature branch", "allow mainline commits"). If so, skip branch creation and proceed with the commit.
-
-Otherwise, automatically create a feature branch:
-
-1. Inform user: "You're on the `{mainline}` branch. Creating a feature branch."
-2. Invoke the `branch` skill using the Skill tool
-3. After branch created, continue with commit process
-
-**Verify there are changes to commit:**
+**Verify there are changes to commit:**
 
 Check the "Status" and "Staged changes" to see if there are any changes to commit. If no changes exist, inform the user there's nothing to commit and exit early.
+
+**If on mainline branch:**
+
+Check if the user's prompt or project CLAUDE.md explicitly allows committing directly to mainline (e.g., "commit to main", "no feature branch", "allow mainline commits"). If so, skip branch creation and proceed with the commit.
+
+Otherwise, automatically create a feature branch:
+
+1. Inform user: "You're on the `{mainline}` branch. Creating a feature branch."
+2. Invoke the `branch` skill using the Skill tool
+3. After branch created, continue with commit process

As per coding guidelines, “All skills should check prerequisites (uncommitted changes, base branch, not on mainline) before doing detection work.”

@cblecker
cblecker merged commit 700f26b into main Feb 11, 2026
9 checks passed
@cblecker
cblecker deleted the feat/auto-branch-on-mainline branch February 11, 2026 03:43
cblecker added a commit that referenced this pull request Mar 11, 2026
Add explicit NEVER rule to the Git Safety Protocol prohibiting direct
commits to the mainline branch unless the user explicitly requests it.
This protection was present in the old skill-based architecture (PR #12)
but was lost during the SessionStart rewrite.

Assisted-by: Claude:claude-opus-4-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant