Always Branch From Remote Master
Rule
Create new branches from origin/master, never from local HEAD with uncommitted work.
Context
When creating feature branches for PRs, branching from local commits that aren't on master causes PRs to contain unrelated commits.
Detection
Observable signals:
- PR contains commits not mentioned in title/description
- PR requires rebase for clean review
- Reviewer questions why extra commits are present
git log origin/master..HEADshows local commits before branching
Pattern
Wrong - branches from current HEAD:
# DON'T: Branches from wherever you are now
git checkout -b fix/my-feature
Correct - branches from remote master:
# Fetch latest master
git fetch origin master
# Create branch from origin/master
git checkout -b fix/my-feature origin/master
# Verify clean base
git log origin/master..HEAD # Should show 0 commits initially
For project monitoring:
# Before creating branch for PR work
cd projects/gptme
git fetch origin master
git checkout master
git pull origin master
# Now create feature branch
git checkout -b fix/issue-123
Outcome
Following this pattern:
- PRs contain only relevant commits
- Clean git history
- Easy review process
- No rebasing required
- Matches PR description exactly
Warning: follow-on push trap
Branching from origin/master sets the new branch's upstream to origin/master.
Under push.default=upstream, git push -u origin BRANCH then resolves to
BRANCH:master — your feature commit lands on master with no PR.
Always push feature branches with an explicit refspec:
git push -u origin my-feature:my-feature
See Worktree Push Trap for the full writeup and recovery options.
Related
- Worktree Push Trap - The follow-on trap this pattern creates
- Git Worktree Workflow - Worktree management
- Git Workflow - General git practices
- When to Rebase PRs - Rebase guidance