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
6/2/2026
Claude Code
#git#sync#branch#worktree

Recommended for

Automated summary

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.
How this analysis is made

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

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/git-sync-mm8o51xo/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/git-sync-mm8o51xo' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/git-sync-mm8o51xo/download' --output '.skill-downloads/git-sync-mm8o51xo/SKILL.md.part' && mv '.skill-downloads/git-sync-mm8o51xo/SKILL.md.part' '.skill-downloads/git-sync-mm8o51xo/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/git-sync-mm8o51xo/SKILL.md' && test -s '.skill-downloads/git-sync-mm8o51xo/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/git-sync' && cp -R '.skill-downloads/git-sync-mm8o51xo' '.claude/skills/git-sync'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/git-sync-mm8o51xo'

openskills read 'git-sync-mm8o51xo'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/git-sync-mm8o51xo/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills