Skip to content

git feature new: record a base branch when started from a detached HEAD - #40

Merged
martyzz1 merged 1 commit into
masterfrom
feature/detached-head-base
Nov 7, 2026
Merged

martyzz1 merged 1 commit into
masterfrom
feature/detached-head-base

Conversation

@martyzz1

@martyzz1 martyzz1 commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Worktrees made with git worktree add --detach ../<repo>-eng-NNNN origin/main and then echo y | git feature new <branch> recorded no base branch. _record_base_if_branch only recorded a local branch, and the reflog says only Created from HEAD. So git pullrequest asked "Was it main?", and in a script it gave up. All 11 Harper ENG-2110 PRs needed git pullrequest --base main.

Behaviour

Starting point What happens
Detached at the tip of origin/<masterBranch> or the local masterBranch Records masterBranch without asking, and skips the "You aren't on your main branch" question
Detached elsewhere, answer on stdin Asks HEAD is detached. Which branch is <new_branch> based on? [<masterBranch>] (Enter = masterBranch), checks the answer is on origin
Detached elsewhere, no answer on stdin (e.g. echo y | git feature new x) Exits before creating the branch: no answer on stdin. Rerun with --base <branch>…. Never guesses
git feature new <name> --base <branch> Records <branch> (must be on origin), asks nothing, matching git pullrequest --base
From a local branch Unchanged: that branch is recorded

git release new / git hotfix new (_branch_func) get the same detached-HEAD handling, but not --base.

Changes

  • gitfeatures/core.py: _record_base_if_branch is replaced by _detached_at_master_tip and _base_for_new_branch, which reuse _ref_exists, _record_base_branch and the existing "not on origin" message. The base is resolved before git checkout -b, so a bad answer leaves nothing behind.
  • tests/test_feature_new.py: 5 cases (detached at the master tip, prompt answered, answer not on origin, no answer on stdin, --base).
  • README: detached-HEAD rules under "Base branches", the git feature new reference, and a troubleshooting entry. CHANGELOG: a "Fixed" entry.

Testing

pytest: 82 passed. flake8, black (-l 119) and rst-lint are clean.

No version bump.

🤖 Generated with Claude Code

Worktrees made with `git worktree add --detach <path> origin/main` left
nothing recorded, so `git pullrequest` had to ask, and in a script it gave up.

- Detached at the tip of origin/<masterBranch> (or the local one): record
  masterBranch without asking.
- Detached elsewhere: ask which branch, default masterBranch, check it is on
  origin. No answer on stdin: exit before creating the branch, asking for --base.
- `git feature new <name> --base <branch>` records the base without asking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martyzz1
martyzz1 merged commit 9aea262 into master Nov 7, 2026
12 checks passed
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