Loading...
Loading...
Sync the current feature branch with origin/main by committing local work, fetching, merging, and resolving conflicts. Use when user says 'merge main', 'update from main', 'sync with main', 'pull main into branch', 'branch is behind main', or 'update my branch'. Do NOT use for creating PRs (use create-pr), reviewing code (use review-diff), or any rebase workflow — this skill does merge, not rebase.
npx skill4agent add thommann/skills merge-mainorigin/mainCLAUDE.md.github/git status
git diff --statgit add <specific-files> # prefer listing files over `git add -A`
git commit -m "type(scope): concise message"CLAUDE.md.github/type(scope): messagegit fetch origin main
behind=$(git log --oneline HEAD..origin/main | wc -l)
ahead=$(git log --oneline origin/main..HEAD | wc -l)
echo "Branch is $behind commits behind and $ahead ahead of origin/main."behindgit log --oneline HEAD..origin/main
git diff --stat HEAD...origin/maingit diff --name-only HEAD...origin/main > /tmp/main_changes.txt
git diff --name-only origin/main...HEAD > /tmp/branch_changes.txt
comm -12 <(sort /tmp/main_changes.txt) <(sort /tmp/branch_changes.txt)git merge origin/maingit diff --name-only --diff-filter=Ugit log --oneline -5 origin/main -- <file>package-lock.jsonpnpm-lock.yamluv.lockCargo.lockgit add <resolved-file>git commit # use the default merge message; do not amend# Regenerate lockfile if the package manifest changed on main
# (pick the one your project uses)
# pnpm install # if pnpm-lock.yaml was conflicted or package.json changed
# uv lock # if uv.lock was conflicted
# cargo check # validates Cargo.toml + Cargo.lock
# Re-run lint/typecheck to catch merge mistakes
# (use the project's command from Quick Reference in CLAUDE.md)git add <regenerated-files>
git commit -m "chore: post-merge regen after syncing with main"review-diffgit rebase# No conflicts remain
git status
# Expected: "nothing to commit, working tree clean" (or only the merge commit)
# Branch is now up to date with origin/main
git log --oneline HEAD..origin/main | wc -l
# Expected: 0
# Lint/typecheck passes (project-specific command from CLAUDE.md)| Mistake | Correction |
|---|---|
Running | Commit first (step 1). Stashing loses the conventional-commit message. |
| Accepting one side of a lockfile conflict without regenerating | Accept either side, THEN run the package manager's regen command. Otherwise the lockfile drifts from the manifest. |
| Resolving a function-body conflict by deleting one side | Never drop real changes silently. If unsure which side's intent wins, ask. |
| Force-pushing to rewrite the merge commit | Merge commits stay. If the merge was wrong, create a revert commit instead. |