Merge master

From keybase/client · View interactive version

Merge master is an AI agent skill from the GitHub repository keybase/client. Use when periodically merging upstream master commits into a long-running refactor branch where code has moved, been renamed, or restructured — guiding careful per-commit analysis and transplant rather than a raw git merge.

How to use this skill

Skill file

Merge Master into Refactor Branch

Use this skill when you need to bring upstream master changes into a long-running refactor branch. A raw git merge master often produces conflicts in code that has moved or been restructured. Instead, analyze each master commit individually and apply the equivalent change to wherever that code now lives.

Find the Last Merge Point

# Find the last time master was merged into this branch
git log --oneline --merges | grep -i master | head -3
# Note the commit hash and date
git log <hash> --format="%ai %s" -1

Get New Master Commits Since Last Merge

# Find the master commit that was merged last time (parent 2 of the merge commit)
git log <last-merge-hash>^2 --oneline -1

# List all master commits since then, oldest first
git log <master-tip-at-last-merge>..origin/master --oneline --reverse

Per-Commit Analysis

For each commit in master since the last merge:

  1. Inspect the diff:

```bash

git show <commit> --stat

git show <commit> --name-only # full file list first

git show <commit> # full diff

```

  1. Determine applicability. A commit may:
  1. Locate the target. Files may have moved. Use search:

```bash

cd shared && grep -r "functionName\|ClassName" --include=".ts" --include=".tsx" -l

```

  1. Apply the equivalent change — not a copy-paste of the diff, but the same intent applied to the current structure. Common cases:
  1. Cover ALL file types. A single commit often touches multiple languages. For each commit, verify you've addressed every file in git show <commit> --name-only — TS/TSX, Go, Kotlin, Swift, Java, tests, etc. Missing one language (e.g. applying TS changes but skipping Go) is a common failure mode.

When to Stop and Ask

Stop and ask the user before proceeding when:

State clearly: what the master commit does, where you expected to find it, and what you found instead.

Skipping Commits

If a commit is already applied or clearly irrelevant, document the skip inline:

SKIP <hash> "<title>" — reason (already applied in <our-commit> / not relevant)

Final Cross-Reference Check

Before validating, do a completeness pass to catch anything missed:

# 1. List every file touched across ALL master commits being merged
git show <commit1> <commit2> ... --name-only | sort -u

# 2. For each file, confirm one of:
#    - Applied: we made an equivalent change
#    - Skipped: documented reason (already done / not relevant)
#    - N/A: the feature doesn't exist in our branch and that's intentional

Work through this list explicitly, file by file. If any file has no status, investigate before marking done.

Validation

After all commits are processed:

TypeScript (from shared/):

yarn lint:all

Go (from go/):

go build ./...

Fix any issues before reporting done. If lint or tsc surfaces problems in unrelated code, note them separately — don't silently expand scope.

Alternative: git merge + Conflict Resolution

For large batches of master commits, git merge origin/master can be more efficient — it surfaces exactly what conflicts:

git merge origin/master
# Resolve each conflict file using the skill logic:
# - Our branch's structure wins (keep our patterns, interfaces, imports)
# - Master's intent is applied (keep the new behavior/logic)
# - Never blindly accept "ours" or "theirs" — understand what each side does
git add <resolved-files>
git merge --continue

Use this approach when there are many commits and the conflict markers clearly show the divergence. Use the per-commit approach when conflicts are ambiguous or when you need to understand each change's intent before applying it.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.