Skip to content

Sync a local main branch to the latest upstream or origin code, handling both fork and owned repos.

CCM score
52 of 100
skills.sh installs
3.4K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers two cases: forks sync from an official remote and force-push to origin, while owned projects pull from origin
  • Runs git remote -v, git fetch, git checkout, and git log --oneline -5 to detect the main branch and verify the result
  • Enforces --force-with-lease instead of --force when pushing a fork, and warns about uncommitted changes before resetting
  • Triggered when a user asks to pull upstream changes, update the main branch, or fetch the latest main code

Install

$ npx -y skills add zc277584121/mygitplugin --skill git-sync-main -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Git Sync Main

同步最新主分支代码到本地并切换到主分支。支持两种场景:fork 的项目从 official remote 同步,自己的项目从 origin 同步。

触发条件

当用户要求同步上游代码、更新主分支、或拉取最新主分支代码时使用此 skill。

执行步骤

  1. 检查 remote 配置:git remote -v,确认是否存在 official remote。

  2. 根据是否存在 official remote 分两种情况执行:

情况一:存在 official remote(fork 的项目)

  1. 检测主分支名称:通过 git remote show official 或查看本地分支,确定主分支名称(main 或 master)。

  2. 拉取 official 最新代码:git fetch official。

  3. 切换到本地主分支:git checkout <main-branch>。

  4. 同步代码:git reset --hard official/<main-branch>,将本地主分支重置到 official 最新状态。

  5. 推送到 origin:git push origin <main-branch> --force-with-lease,同步自己 fork 的远端主分支。

情况二:不存在 official remote(自己的项目)

  1. 检测主分支名称:通过查看本地分支,确定主分支名称(main 或 master)。

  2. 拉取 origin 最新代码:git fetch origin。

  3. 切换到本地主分支:git checkout <main-branch>。

  4. 同步代码:git pull origin <main-branch>,将本地主分支同步到 origin 最新状态。

共同步骤

  1. 验证结果:git log --oneline -5,展示最新的几条 commit 确认同步成功。

注意事项

  • 始终使用 official 作为上游 remote 名称(而非 upstream),以保持一致性。
  • 对于 fork 项目,推送到 origin 时使用 --force-with-lease 而非 --force,更安全地强制推送。
  • 如果当前有未提交的改动,先提示用户处理(stash 或 commit),避免丢失工作。

Details

Repository
github.com/zc277584121/mygitplugin
Category
Git & Releases
First seen
Jun 3, 2026

Questions

What does the git-sync-main skill do?

It syncs your local main branch with the latest code from an official upstream or origin remote, then switches to main. For forks it resets to the official remote and pushes to origin with force-with-lease. For your own projects it pulls from origin.

Which Git & Releases skills lead this one?

git-sync-main ranks in the top 100 on the Git & Releases category page, alongside triage, git-guardrails-claude-code, setup-pre-commit, caveman-commit and pr. It is aimed at keeping a local main branch current rather than at committing or review work.

How do I install git-sync-main?

Run npx -y skills add zc277584121/mygitplugin --skill git-sync-main -y in your project. Once installed, the agent can sync your local main branch with the latest upstream or origin code and show the recent commits to confirm.

Does git-sync-main need anything before it runs?

It needs Git with an official or origin remote configured, and the Bash tool is in its allowed tools. The README also notes that the gh CLI should be authenticated. If you have uncommitted changes, the skill asks you to stash or commit them first.

More from zc277584121/mygitplugin

All 7

Similar to Git Sync Main

More Git & Releases