PluginBench
Skill
Pass
Audit score 90

git-sync-main

zc277584121/mygitplugin

Sync your local main branch with upstream or origin remote in one command

What is git-sync-main?

Automatically synchronizes your local main branch with the latest code from either an official upstream remote (for forked projects) or origin remote (for your own projects). Use this when you need to update your main branch to the latest version before starting new work.

  • Detects whether your repository is a fork (has official remote) or standalone project
  • Fetches latest code from the appropriate remote (official or origin)
  • Automatically detects main branch name (main or master)
  • Safely resets or pulls your local main branch to match upstream
  • Pushes synchronized changes back to your fork using force-with-lease for safety
  • Verifies sync success by displaying recent commit history

How to install git-sync-main

npx skills add https://github.com/zc277584121/mygitplugin --skill git-sync-main
Prerequisites
  • Git installed and configured
  • A local Git repository with either an 'official' remote (for forks) or 'origin' remote (for standalone projects)
Claude Code
Cursor
Windsurf
Cline

How to use git-sync-main

  1. 1.Run the skill when you need to sync your main branch
  2. 2.The skill will check your remote configuration automatically
  3. 3.If you have uncommitted changes, stash or commit them first
  4. 4.The skill will fetch from the appropriate remote and update your local main branch
  5. 5.Review the commit log displayed to confirm the sync was successful

Use cases

Good for
  • Update your forked repository's main branch before submitting a pull request
  • Sync your local development branch with the latest upstream changes
  • Prepare your repository for new feature development by ensuring main is current
  • Resolve conflicts by resetting to a known-good upstream state
  • Keep multiple local clones synchronized with a central repository
Who it's for
  • Git users working with forked repositories
  • Developers maintaining their own projects
  • Team members needing to stay synchronized with upstream code
  • Contributors to open-source projects

git-sync-main FAQ

What's the difference between syncing a forked project vs. my own project?

For forked projects with an 'official' remote, the skill fetches from official and force-pushes to your origin fork. For your own projects, it simply pulls from origin. Both end with your local main branch matching the upstream source.

Why does it use force-with-lease instead of force?

force-with-lease is safer because it only force-pushes if no one else has pushed to that branch since your last fetch, preventing accidental overwrites of others' work.

What if I have uncommitted changes?

The skill will prompt you to handle them first—either stash your changes or commit them—to prevent losing work during the sync.

How do I know if the sync succeeded?

The skill displays the last 5 commits with git log --oneline. Verify that the commit hashes and messages match what you expect from upstream.

What if my repository uses 'master' instead of 'main'?

The skill automatically detects whether your main branch is named 'main' or 'master' and uses the correct name.

Full instructions (SKILL.md)

Source of truth, from zc277584121/mygitplugin.


name: git-sync-main description: Sync local main branch with the latest code from official upstream or origin remote allowed-tools:

  • Bash

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