Back to Skills

git-sync-main

Sync local main branch with the latest code from official upstream or origin remote

Updated 7/14/2026

Security Assessment

Safe(100/100)
Security Score100/100

About git-sync-main

git-sync-main synchronizes a local main branch with the latest code from either an official upstream remote or the origin remote, then leaves the user checked out on the main branch. It solves the common friction of keeping a working copy up to date across two distinct situations: a forked project that must pull from an upstream remote, and a personal project that pulls directly from origin. The skill is triggered when the user asks to sync upstream code, update the main branch, or pull the latest main branch code.

The workflow begins by inspecting remotes with git remote -v to determine whether an official remote exists. If it does (a fork), the skill detects the main branch name (main or master) via git remote show official, fetches with git fetch official, checks out the local main branch, resets it to the upstream state with git reset --hard official/<main-branch>, and then pushes the fork's own remote with git push origin <main-branch> --force-with-lease. If there is no official remote (a personal project), it instead fetches origin, checks out main, and runs git pull origin <main-branch>. Both paths end with git log --oneline -5 to confirm the sync succeeded.

The skill is aimed at developers who maintain forks or personal repositories and want a consistent, safe update routine. It deliberately standardizes on the remote name official rather than upstream for consistency, and uses --force-with-lease instead of --force when pushing to a fork's origin for safer forced updates. A stated precaution is to prompt the user to handle any uncommitted changes (stash or commit) before syncing so work is not lost. The skill declares allowed-tools of Bash only. Note that the documentation is written primarily in Chinese.

FAQ

What is the difference between the two sync scenarios?

If an 'official' remote exists (a forked project), the skill fetches from official, resets local main hard to official/<main-branch>, and force-pushes to origin with --force-with-lease. If there is no official remote (your own project), it fetches origin and runs git pull origin <main-branch>.

Why does it use 'official' instead of 'upstream'?

The skill deliberately standardizes on 'official' as the upstream remote name rather than 'upstream' to keep naming consistent across projects.

What happens if I have uncommitted changes?

The notes instruct that if there are uncommitted local changes, the user should be prompted to handle them first (stash or commit) to avoid losing work before syncing.

Why --force-with-lease instead of --force?

For fork projects, pushing to origin uses git push origin <main-branch> --force-with-lease rather than --force because it is a safer way to force-push, avoiding overwriting remote commits you have not seen.

How does it confirm the sync worked?

As a common final step it runs git log --oneline -5 to display the latest few commits and verify the sync completed successfully.

Install git-sync-main

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill