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- Git installed and configured
- A local Git repository with either an 'official' remote (for forks) or 'origin' remote (for standalone projects)
How to use git-sync-main
- 1.Run the skill when you need to sync your main branch
- 2.The skill will check your remote configuration automatically
- 3.If you have uncommitted changes, stash or commit them first
- 4.The skill will fetch from the appropriate remote and update your local main branch
- 5.Review the commit log displayed to confirm the sync was successful
Use cases
- 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
- 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
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.
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.
The skill will prompt you to handle them first—either stash your changes or commit them—to prevent losing work during the sync.
The skill displays the last 5 commits with git log --oneline. Verify that the commit hashes and messages match what you expect from upstream.
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。
执行步骤
-
检查 remote 配置:
git remote -v,确认是否存在officialremote。 -
根据是否存在 official remote 分两种情况执行:
情况一:存在 official remote(fork 的项目)
-
检测主分支名称:通过
git remote show official或查看本地分支,确定主分支名称(main或master)。 -
拉取 official 最新代码:
git fetch official。 -
切换到本地主分支:
git checkout <main-branch>。 -
同步代码:
git reset --hard official/<main-branch>,将本地主分支重置到 official 最新状态。 -
推送到 origin:
git push origin <main-branch> --force-with-lease,同步自己 fork 的远端主分支。
情况二:不存在 official remote(自己的项目)
-
检测主分支名称:通过查看本地分支,确定主分支名称(
main或master)。 -
拉取 origin 最新代码:
git fetch origin。 -
切换到本地主分支:
git checkout <main-branch>。 -
同步代码:
git pull origin <main-branch>,将本地主分支同步到 origin 最新状态。
共同步骤
- 验证结果:
git log --oneline -5,展示最新的几条 commit 确认同步成功。
注意事项
- 始终使用
official作为上游 remote 名称(而非upstream),以保持一致性。 - 对于 fork 项目,推送到 origin 时使用
--force-with-lease而非--force,更安全地强制推送。 - 如果当前有未提交的改动,先提示用户处理(stash 或 commit),避免丢失工作。
Related skills
More from zc277584121/mygitplugin and the wider catalog.

git-commit-pr
Commit changes and create pull requests to upstream repositories with proper review and attribution.

git-commit-push
Commit changes and push to origin without creating a PR

git-create-repo
Create a new GitHub repository and clone it locally with a single command

git-fork-clone
Fork a GitHub repo and clone it locally with automatic upstream remote setup

perpetuum
Establish, run, and manage long-term Agent teams across one or more projects with persistent Story boards and cron scheduling.
brand-writer
Write clear, developer-first copy for Zed — leading with facts, grounded in craft.