fix(git): add git.base_branch config to replace hardcoded main target

Adds `git.base_branch` config option that controls the target branch
for PRs and merges. When unset, auto-detects from origin/HEAD and
falls back to "main".

This fixes projects using `master`, `develop`, or any other default
branch — previously `/gsd:ship` would create PRs targeting `main`
(which may not exist) and `/gsd:complete-milestone` would try to
checkout `main` and fail.

Changes:
- config.cjs: add git.base_branch to valid config keys
- planning-config.md: document the option with auto-detect behavior
- ship.md: detect base branch at init, use in PR create, branch
  detection, push report, and completion report
- complete-milestone.md: detect base branch, use for squash merge
  and merge-with-history checkout targets
- 1 new test for config-set git.base_branch

Usage:
  gsd-tools config-set git.base_branch master

Or auto-detect (default — reads origin/HEAD):
  git.base_branch: null

Closes #1466

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tibsfox
2026-03-29 06:06:33 -07:00
parent 78e5c6d973
commit 0fb992d151
5 changed files with 37 additions and 7 deletions

View File

@@ -537,6 +537,15 @@ if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
Extract `branching_strategy`, `phase_branch_template`, `milestone_branch_template`, and `commit_docs` from init JSON.
Detect base branch:
```bash
BASE_BRANCH=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" config-get git.base_branch 2>/dev/null || echo "")
if [ -z "$BASE_BRANCH" ] || [ "$BASE_BRANCH" = "null" ]; then
BASE_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|^refs/remotes/origin/||')
BASE_BRANCH="${BASE_BRANCH:-main}"
fi
```
**If "none":** Skip to git_tag.
**For "phase" strategy:**
@@ -575,7 +584,7 @@ AskUserQuestion with options: Squash merge (Recommended), Merge with history, De
```bash
CURRENT_BRANCH=$(git branch --show-current)
git checkout main
git checkout ${BASE_BRANCH}
if [ "$BRANCHING_STRATEGY" = "phase" ]; then
for branch in $PHASE_BRANCHES; do
@@ -604,7 +613,7 @@ git checkout "$CURRENT_BRANCH"
```bash
CURRENT_BRANCH=$(git branch --show-current)
git checkout main
git checkout ${BASE_BRANCH}
if [ "$BRANCHING_STRATEGY" = "phase" ]; then
for branch in $PHASE_BRANCHES; do

View File

@@ -24,6 +24,15 @@ CONFIG=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" state load)
```
Extract: `branching_strategy`, `branch_name`.
Detect base branch for PRs and merges:
```bash
BASE_BRANCH=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" config-get git.base_branch 2>/dev/null || echo "")
if [ -z "$BASE_BRANCH" ] || [ "$BASE_BRANCH" = "null" ]; then
BASE_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|^refs/remotes/origin/||')
BASE_BRANCH="${BASE_BRANCH:-main}"
fi
```
</step>
<step name="preflight_checks">
@@ -46,7 +55,7 @@ Verify the work is ready to ship:
```bash
CURRENT_BRANCH=$(git branch --show-current)
```
If on `main`/`master`: warn — should be on a feature branch.
If on `${BASE_BRANCH}`: warn — should be on a feature branch.
If branching_strategy is `none`: offer to create a branch now.
4. **Remote configured?**
@@ -74,7 +83,7 @@ If push fails (e.g., no upstream): set upstream:
git push --set-upstream origin ${CURRENT_BRANCH} 2>&1
```
Report: "Pushed `{branch}` to origin ({commit_count} commits ahead of main)"
Report: "Pushed `{branch}` to origin ({commit_count} commits ahead of ${BASE_BRANCH})"
</step>
<step name="generate_pr_body">
@@ -141,7 +150,7 @@ Create the PR using the generated body:
gh pr create \
--title "Phase ${PHASE_NUMBER}: ${PHASE_NAME}" \
--body "${PR_BODY}" \
--base main
--base ${BASE_BRANCH}
```
If `--draft` flag was passed: add `--draft`.
@@ -194,7 +203,7 @@ node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" commit "docs(${padded_phase
## ✓ Phase {X}: {Name} — Shipped
PR: #{number} ({url})
Branch: {branch} → main
Branch: {branch} → ${BASE_BRANCH}
Commits: {count}
Verification: ✓ Passed
Requirements: {N} REQ-IDs addressed