SuperAPI AI Directory

git-sync-main

Coding & development

View repository

Updated 10-16 09:14

About this skill

Git Sync Main

Sync the latest main branch code to local and switch to the main branch. Supports two scenarios: forked projects sync from the official remote, and your own projects sync from origin.

Trigger Conditions

Use this skill when the user requests syncing upstream code, updating the main branch, or pulling the latest main branch code.

Execution Steps

  1. Check remote configuration:git remote -v, confirm whether official remote。

  2. Execute in two cases depending on whether an official remote exists:

Case 1: official remote exists (forked project)

  1. Detect the main branch name: via git remote show official or by checking local branches, determine the main branch name (main or master)。

  2. Pull the latest official code:git fetch official。

  1. Switch to the local main branch:git checkout <main-branch>。

  2. Sync code:git reset --hard official/<main-branch>, reset the local main branch to the latest official state.

  3. Push to origin:git push origin <main-branch> --force-with-lease, sync the remote main branch of your own fork.

Case 2: official remote does not exist (your own project)

  1. Detect the main branch name: by checking local branches, determine the main branch name (main or master)。

  2. Pull the latest origin code:git fetch origin。

  3. Switch to the local main branch:git checkout <main-branch>。

  4. Sync code:git pull origin <main-branch>, sync the local main branch to the latest origin state.

Common Steps

  1. Verify the result:git log --oneline -5, display the latest few commits to confirm the sync succeeded.

Notes

  • Always use official as the upstream remote name (instead of upstream), to maintain consistency.
  • For forked projects, when pushing to origin use --force-with-lease instead of --force, for a safer force push.
  • If there are currently uncommitted changes, first prompt the user to handle them (stash or commit), to avoid losing work.