
Git Sync Main
Reset or pull local main to match official (fork) or origin so your agent branch starts from the latest upstream commits.
Overview
git-sync-main is an agent skill most often used in Build (also Operate/iterate) that syncs local main or master with official or origin using a fork-aware Bash workflow.
Install
npx skills add https://github.com/zc277584121/mygitplugin --skill git-sync-mainWhat is this skill?
- Branches on whether official remote exists: hard reset from official for forks vs git pull from origin for owned repos
- Detects main vs master automatically via git remote show official or local branches
- Fork path pushes to origin with --force-with-lease after reset for safer forced updates
- Standardizes upstream remote name as official (not upstream)
- Ends with git log --oneline -5 to verify sync and warns about uncommitted changes before destructive reset
- 8 numbered execution steps including verification
- 2 remote scenarios (official fork vs origin-only)
Adoption & trust: 379 installs on skills.sh; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your local main is behind upstream or your fork’s origin, and you need a reliable agent procedure that handles forks vs owned repos without losing work silently.
Who is it for?
Solo developers and coding agents maintaining forks or solo repos who trigger sync via natural language and want deterministic remote naming.
Skip if: Repos that need merge-based sync with local commits on main, nonstandard default branch names without detection, or environments where Bash/git is unavailable.
When should I use this skill?
User asks to sync upstream code, update the main branch, or pull the latest primary branch code.
What do I get? / Deliverables
Local main matches official or origin HEAD, fork origin is updated when applicable, and the last five commits confirm the sync.
- Local main/master aligned to official or origin
- Optional origin update on forks
- Oneline log snippet proving latest commits
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Keeping main current is a daily integration task while building and iterating, so Build/integrations is the primary shelf for git remote workflows. The skill wires remotes, fetch, reset/pull, and push—tooling integration around git rather than feature code or release QA alone.
Where it fits
Before cutting a feature branch, sync main from official so your agent PR rebases on the latest upstream commits.
After upstream ships a hotfix, reset local main and push your fork so local agents stop reproducing fixed bugs.
Right before a release tag, pull origin main to ensure your solo repo matches remote before running ship checks.
How it compares
Use this skill instead of ad-hoc git advice that picks random upstream remote names or uses --force without --force-with-lease on forks.
Common Questions / FAQ
Who is git-sync-main for?
Builders using Claude Code or similar agents with Bash who regularly sync main after upstream changes on forked or personal repositories.
When should I use git-sync-main?
Use it before starting Build feature branches, when Operate/iterate after upstream fixes land, or anytime the user asks to sync upstream, update main, or pull the latest primary branch.
Is git-sync-main safe to install?
It can run git reset --hard and force-with-lease pushes; review the Security Audits panel on this page and stash or commit local work before invoking on dirty trees.
SKILL.md
READMESKILL.md - Git Sync Main
# Git Sync Main 同步最新主分支代码到本地并切换到主分支。支持两种场景:fork 的项目从 official remote 同步,自己的项目从 origin 同步。 ## 触发条件 当用户要求同步上游代码、更新主分支、或拉取最新主分支代码时使用此 skill。 ## 执行步骤 1. **检查 remote 配置**:`git remote -v`,确认是否存在 `official` remote。 2. **根据是否存在 official remote 分两种情况执行**: ### 情况一:存在 official remote(fork 的项目) 3. **检测主分支名称**:通过 `git remote show official` 或查看本地分支,确定主分支名称(`main` 或 `master`)。 4. **拉取 official 最新代码**:`git fetch official`。 5. **切换到本地主分支**:`git checkout <main-branch>`。 6. **同步代码**:`git reset --hard official/<main-branch>`,将本地主分支重置到 official 最新状态。 7. **推送到 origin**:`git push origin <main-branch> --force-with-lease`,同步自己 fork 的远端主分支。 ### 情况二:不存在 official remote(自己的项目) 3. **检测主分支名称**:通过查看本地分支,确定主分支名称(`main` 或 `master`)。 4. **拉取 origin 最新代码**:`git fetch origin`。 5. **切换到本地主分支**:`git checkout <main-branch>`。 6. **同步代码**:`git pull origin <main-branch>`,将本地主分支同步到 origin 最新状态。 ### 共同步骤 8. **验证结果**:`git log --oneline -5`,展示最新的几条 commit 确认同步成功。 ## 注意事项 - 始终使用 `official` 作为上游 remote 名称(而非 `upstream`),以保持一致性。 - 对于 fork 项目,推送到 origin 时使用 `--force-with-lease` 而非 `--force`,更安全地强制推送。 - 如果当前有未提交的改动,先提示用户处理(stash 或 commit),避免丢失工作。