Sync Main After Merge
Use this skill for merge-completion tasks on the default branch.
- Identify the repo's default branch.
- Prefer
origin/HEADwhen it exists. - Fall back to
main, thenmaster.
- Prefer
- Check the target checkout for a clean worktree.
- If uncommitted or untracked changes exist, stop before overwriting anything.
- Fetch and prune remote refs.
git fetch origin --prune
- If the request includes the merge itself, merge the topic branch or worktree branch into the default branch first.
- Switch to the default branch first, then merge the branch the user named or the branch currently associated with the worktree.
- Prefer fast-forward or the repo's documented merge policy.
- If the default branch is protected, do not push directly; route the merge through a pull request, then continue after the PR lands.
- Switch to the default branch locally.
git switch <default-branch>- If
git switchfails because the branch is already checked out in another worktree, stop and resolve that worktree instead of forcing a duplicate checkout.
- Sync the local default branch with remote.
- Use
git pull --ff-onlyfor the normal case. - If the user explicitly wants the local branch to match
origin/<default-branch>exactly, confirm that dropping any local commits is acceptable and the worktree is clean, then usegit reset --hard origin/<default-branch>after fetching. - After a protected-branch PR merges, fetch again before pulling so the local branch sees the new remote commit.
- Use
- Verify the result.
git status --short --branch- Confirm the local branch and
origin/<default-branch>point to the expected commit.
Guardrails
- Use
git switch, notgit checkout. - Never discard local changes unless the user explicitly asked for an exact remote match.
- Do not assume
main; usemasteronly when that is the actual default branch. - If the target branch is ambiguous, resolve that before changing history.