Sync Git
Usage
Run the sync script from the repo root. The script may be installed at the project level or the user level, so resolve the path before running (project level takes precedence):
SYNC=".claude/skills/sync-git/scripts/sync.sh"
[ -f "$SYNC" ] || SYNC="$HOME/.claude/skills/sync-git/scripts/sync.sh"
bash "$SYNC"
Interpret output
- exit 0 — Success. Show the stdout summary to the user. Done.
- exit 1 — Worktree detected. Follow Fallback: Worktree below.
- exit 2 — Rebase conflict. Follow Fallback: Conflict Resolution below.
- exit 3 — Push rejected after 3 retries. Follow Fallback: Push Failure below.
- exit 4 — Network/SSH error. Tell user to check SSH agent or connection.
Fallback: Worktree
If running inside a worktree (not the main working tree):
- Commit any uncommitted changes in the worktree branch.
- Determine the main working tree's branch:
MAIN_TREE="$(git worktree list | head -1 | awk '{print $1}')" TARGET_BRANCH="$(git -C "$MAIN_TREE" branch --show-current)" - Switch to the main repo and merge:
If there are conflicts, resolve using Fallback: Conflict Resolution rules.cd "$MAIN_TREE" git merge <worktree-branch> --no-edit - Clean up the worktree (remove it after successful merge):
If merge failed, leave the worktree intact and report the error. Then re-run the sync script from the main repo (resolve the path as in Usage).git worktree remove <worktree-path> git branch -d <worktree-branch>
Fallback: Conflict Resolution
When rebase or merge conflicts occur:
- For text/content files (
.md,.txt, etc.): accept both changes — combine content from both sides so no data is lost. - For config/generated files (
.json, lock files, etc.): accept theirs (remote) to keep config in sync across machines. - After resolving:
git add -A git rebase --continue
Then re-run the sync script to push.
Fallback: Push Failure
If push is still rejected after script retries:
- Run
git fetch originandgit log --oneline origin/<branch>..HEADto understand divergence. - Try
git pull --rebase origin <branch>manually, resolving any conflicts per rules above. - Push again. If still failing, report to user.