Synchronisation Git

VérifiéPrudence

Synchronise la branche par défaut locale avec sa branche distante pour garantir qu'elle est à jour avant la création de nouveaux worktrees. Gère les modifications non validées, l'échec de détection automatique et les divergences, en fournissant des messages structurés et des options de récupération interactives.

Spar Skills Guide Bot
DeveloppementIntermédiaire
9002/06/2026
Claude Code
#git#sync#branch#worktree

Recommandé pour

Notre avis

Synchronise la branche par défaut locale avec la distante pour garantir une base à jour avant de créer des worktrees.

Points forts

  • Automatise le fetch et le fast-forward de la branche par défaut
  • Fournit une sortie structurée (KEY=VALUE) facile à interpréter
  • Gère les erreurs avec des suggestions claires (stash, reset, branche de récupération)
  • Permet de spécifier une branche alternative si la détection automatique échoue

Limites

  • Ne supporte que le fast-forward, pas le rebase ou le merge
  • Nécessite une intervention humaine en cas de divergences ou de modifications non commitées
  • Ne gère que la branche par défaut, pas les branches de fonctionnalité
Quand l'utiliser

Utilisez cette compétence avant de créer un nouveau worktree ou lorsque vous avez besoin d'une branche de base à jour pour commencer le travail.

Quand l'éviter

Évitez de l'utiliser si vous avez des commits locaux sur la branche par défaut que vous souhaitez conserver sans les déplacer vers une autre branche.

Analyse de sécurité

Prudence
Score qualité88/100

The skill uses a bash script to synchronize Git branches, involving network fetch and potentially destructive local operations. These are controlled and require explicit user choices, but the risk of data loss exists if mishandled.

Points d'attention
  • Executes a bash script that performs network operations (git fetch) and local file modifications.
  • Error handling suggests commands like 'git reset --hard' and 'git stash' which could discard local changes if misused, though user consent is required.

Exemples

Basic sync with auto-detection
Run the git sync skill to bring my default branch up to date with the remote.
Sync with specific branch
Use the git sync skill but force it to sync the 'develop' branch instead of the auto-detected default.
Handle uncommitted changes during sync
The git sync script failed with uncommitted changes. Ask me if I want to stash, discard, or abort.

name: git-sync description: Synchronize local default branch with remote, ensuring up-to-date base for worktrees. allowed-tools:

  • Bash(~/.claude/skills/git-sync/scripts/sync.sh:*)
  • Bash(git stash :*)
  • Bash(git restore :*)
  • Bash(git checkout :*)
  • Bash(git remote -v)

Git Sync

Instructions

Invocation

Run the sync script. The script path is relative to this skill's directory:

~/.claude/skills/git-sync/scripts/sync.sh

To override the default branch (e.g. if auto-detection fails):

~/.claude/skills/git-sync/scripts/sync.sh --branch main

Reading the Output

The script emits structured KEY=VALUE pairs on stdout. Key fields:

| Field | Meaning | |---|---| | GIT_SYNC_STATUS | success or error | | DEFAULT_BRANCH | Detected default branch name | | ORIGINAL_BRANCH | Branch before sync started | | COMMITS_PULLED | Number of new commits pulled (on success) | | LATEST_COMMIT | Latest commit after sync (on success) | | ERROR_CODE | Error type (on failure) | | DETAILS | Error details (on failure) |

On Success (exit code 0)

Report to the user:

Sync complete
- Default branch: <DEFAULT_BRANCH>
- Pulled <COMMITS_PULLED> new commit(s)
- Latest: <LATEST_COMMIT>
- Ready to create new worktrees

If COMMITS_PULLED=0, simply say the branch is already up to date.

Error Handling

Exit 1 — Uncommitted changes (ERROR_CODE=uncommitted_changes)

The default branch has uncommitted changes, which is unexpected. Show the user the DETAILS field (modified files) and ask them to choose:

  1. Stash changes — run git stash push -m "Temp stash before sync", then re-run the sync script
  2. Discard changes — run git restore ., then re-run the sync script
  3. Abort — stop and let the user handle it manually

Exit 2 — Cannot detect default branch (ERROR_CODE=no_default_branch)

The script could not determine the default branch automatically. Ask the user which branch to sync (typically main or master), then re-run with:

~/.claude/skills/git-sync/scripts/sync.sh --branch <user-specified-branch>

Exit 3 — Fast-forward failed (ERROR_CODE=ff_failed)

The local default branch has diverged from remote. The output includes LOCAL_COMMITS and REMOTE_COMMITS showing what diverged. Present these to the user and ask them to choose:

  1. Reset to remote — run git checkout <DEFAULT_BRANCH> && git reset --hard origin/<DEFAULT_BRANCH>, warn this discards local commits
  2. Move local commits to a branch — run git checkout -b recover/<DEFAULT_BRANCH>-commits && git checkout <DEFAULT_BRANCH> && git reset --hard origin/<DEFAULT_BRANCH>
  3. Manual resolution — stop and let the user handle it

After resolving, re-run the sync script to verify.

Exit 4 — Fetch failed (ERROR_CODE=fetch_failed)

Network or remote issue. Report the error and suggest:

  • Check network connectivity
  • Verify remote with git remote -v
  • Retry later
Skills similaires