Use when the user wants to create a new stacked branch, add a branch on top of the current one, or runs /gs-create.
You are implementing /gs-create. This creates a new branch stacked on the current branch, stages and commits any pending changes, and records stack metadata in git config. No pushing, no PRs.
The user may invoke this as /gs-create or /gs-create "feat: add retry logic" (optional commit message argument).
git status --porcelain
If the output shows merge conflicts (lines starting with UU, AA, DD), stop and tell the user to resolve conflicts before creating a stack branch.
Staged and unstaged changes are fine — they will be handled in step 6.
Follow the stack discovery pattern (git config only, no fallback). Display the relevant portion of the stack so the user can see where they are.
Get the current branch name:
git rev-parse --abbrev-ref HEAD
Store it as <current-branch>.
If no stack exists yet (no git-stack.* keys), this will start a new stack. Detect the repository's default branch:
gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
Store the result as <root-branch>. If gh is unavailable, fall back to:
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@'
If both fail, default to main and confirm with the user:
Assuming
mainas the base branch. Is this correct? (yes / type the correct branch name)
Once determined, persist the root:
git config git-stack.root <root-branch>
If the current branch is <root-branch>, note that this will start a new stack.
Read CLAUDE.md (if present) for branch naming conventions. Also look at recent branch names for patterns:
git branch --sort=-committerdate | head -20
Common patterns to look for: type/ticket-slug, user/ticket-description, devin/ticket-id-slug, etc.
If the user passed a commit message argument (e.g. /gs-create "feat: add retry logic"), derive a branch name suggestion from it.
Suggest a branch name and ask the user to confirm or provide a different one. Wait for confirmation before proceeding.
Once the branch name is confirmed, create and switch to it from the current HEAD:
git checkout -b <new-branch>
Record the stack relationship in git config:
git config git-stack.<new-branch>.parent <current-branch>
Follow the safe staging flow pattern. Show the user what will be staged, warn on sensitive files, and stage by name. If there are no changes, ask whether to create an empty branch or cancel; on cancel, undo with git checkout <current-branch> && git branch -D <new-branch> && git config --unset git-stack.<new-branch>.parent.
If the user passed a commit message argument, use it as the suggestion. Otherwise, inspect the staged diff:
git diff --cached --stat
git diff --cached
Suggest a commit message following the project's conventions (Conventional Commits: type(scope): message). Check CLAUDE.md for any project-specific commit conventions.
Show the suggestion and ask the user to confirm or edit it. Wait for confirmation.
Once the message is confirmed, commit:
git commit -m "<confirmed-message>"
Do NOT add Co-Authored-By lines. Do NOT add 🤖 Generated with Claude Code lines.
Run the project's verification commands as defined in CLAUDE.md (e.g., pnpm typecheck, pnpm lint). If no verification commands are found, skip this step.
Report any failures. Do not declare the branch complete until the user has acknowledged any failures.
Show a summary:
/gs-submit to push and open PRs, or /gs-log to see the stack.Co-Authored-By lines to commits.🤖 Generated with Claude Code lines.CLAUDE.md and existing patterns).<root-branch>: This starts a new stack. Parent will be <root-branch>. Proceed normally.git status shows merge conflicts, stop and tell the user to resolve conflicts before creating a stack branch.