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:

Related

Match Keywords

create branch git checkout -b new feature branch PR contains unrelated commits