Always Branch From Remote Master

lesson workflow active workflow/branch-from-master.md View on GitHub

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:

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:

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

Match Keywords

create branch git checkout -b