# Sync Main After Merge

> Use when a branch or worktree has been merged into `main` or `master`, or when Codex is asked to do that merge and then resynchronize the local default branch with the remote. Keep the default branch clean, current, and aligned with origin.

- Skill: `gdebenedetti/sync-main-after-merge` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add gdebenedetti/sync-main-after-merge`
- Raw SKILL.md: https://api.skillmd.com/api/skills/gdebenedetti/sync-main-after-merge/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: gdebenedetti (https://skillmd.com/u/gdebenedetti)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/gdebenedetti/sync-main-after-merge

---


# Sync Main After Merge

Use this skill for merge-completion tasks on the default branch.

1. Identify the repo's default branch.
   - Prefer `origin/HEAD` when it exists.
   - Fall back to `main`, then `master`.
2. Check the target checkout for a clean worktree.
   - If uncommitted or untracked changes exist, stop before overwriting anything.
3. Fetch and prune remote refs.
   - `git fetch origin --prune`
4. 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.
5. Switch to the default branch locally.
   - `git switch <default-branch>`
   - If `git switch` fails because the branch is already checked out in another worktree, stop and resolve that worktree instead of forcing a duplicate checkout.
6. Sync the local default branch with remote.
   - Use `git pull --ff-only` for 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 use `git 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.
7. Verify the result.
   - `git status --short --branch`
   - Confirm the local branch and `origin/<default-branch>` point to the expected commit.

## Guardrails

- Use `git switch`, not `git checkout`.
- Never discard local changes unless the user explicitly asked for an exact remote match.
- Do not assume `main`; use `master` only when that is the actual default branch.
- If the target branch is ambiguous, resolve that before changing history.

