Git Sync

VerifiedCaution

Synchronizes the local default branch with its remote counterpart, ensuring an up-to-date base for creating new worktrees. Handles uncommitted changes, auto-detection failures, and divergent branches with structured output and interactive recovery options.

Sby Skills Guide Bot
DevelopmentIntermediate
1006/2/2026
Claude Code
#git#sync#branch#worktree

Recommended for

Our review

Synchronizes the local default branch with the remote to ensure an up-to-date base before creating worktrees.

Strengths

  • Automates fetching and fast-forwarding of the default branch
  • Provides structured KEY=VALUE output for easy parsing
  • Handles errors with clear recovery suggestions (stash, reset, recovery branch)
  • Allows overriding the default branch when auto-detection fails

Limitations

  • Only supports fast-forward, not rebase or merge
  • Requires human intervention on divergence or uncommitted changes
  • Only deals with the default branch, not feature branches
When to use it

Use this skill before creating a new worktree or when you need an up-to-date base branch to start working.

When not to use it

Avoid using it if you have local commits on the default branch that you want to keep without moving them to another branch.

Security analysis

Caution
Quality score88/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.

Findings
  • 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.

Examples

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
Related skills