Handles the common workflow of syncing your local main branch with the latest upstream code. It checks if you have an "official" remote configured (for forked repos) or falls back to origin (for your own projects), detects whether you're using main or master, fetches the latest changes, and resets your local branch accordingly. For forks, it force pushes to your origin with the safer force-with-lease flag. For your own repos, it does a straightforward pull. The bilingual documentation is thorough, and I appreciate that it prompts you to handle uncommitted changes first instead of just stomping over them. Saves you from typing the same five git commands every time you want to catch up with upstream.

skills.sh installs
3.4K
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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),避免丢失工作。

Sponsors

Details

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

More from zc277584121/mygitplugin

All 7
1getsentry avatarsentry-code-reviewgetsentry/sentry-for-aiAnalyze and resolve Sentry comments on GitHub Pull Requests. Use this when asked to review or fix issues identified by Sentry in PR comments. Can review specifi2.5Kskills.sh installs
2modem-dev avatarhunk-reviewmodem-dev/hunkInteracts with live Hunk diff review sessions via CLI. Inspects review focus, navigates files and hunks, reloads session contents, and adds inline review commen2.4Kskills.sh installs
3cursor avatarget-pr-commentscursor/pluginsFetch and summarize review comments from the active pull request2.3Kskills.sh installs
4langgenius avatarbackend-code-reviewlanggenius/difyUse only when the user explicitly requests a review or audit of backend code under `api/`. Supports pending-change, file-focused, and pasted-diff reviews. Do no2.1Kskills.sh installs
5vince-winkintel avatargitlab-cli-skillsvince-winkintel/gitlab-cli-skillsComprehensive GitLab CLI (glab) command reference and workflows for all GitLab operations via terminal. Use when user mentions GitLab CLI, glab commands, GitLab1.9Kskills.sh installs
6ruvnet avatargithub-project-managementruvnet/rufloComprehensive GitHub project management with swarm-coordinated issue tracking, project board automation, and sprint planning1.4Kskills.sh installs