From e3434858935c842130d3dd079bdafa48bf9658e7 Mon Sep 17 00:00:00 2001 From: Lee Campbell Date: Sun, 22 Mar 2026 16:44:17 +0800 Subject: [PATCH] feat: add sync-git skill and script Add a Claude Code skill and bash script to sync the local repo with upstream, prune stale remote-tracking refs, and delete local branches already merged into main. Co-Authored-By: Claude Opus 4.6 --- .claude/skills/sync-git/SKILL.md | 8 ++++++++ scripts/synch-git.sh | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .claude/skills/sync-git/SKILL.md create mode 100644 scripts/synch-git.sh diff --git a/.claude/skills/sync-git/SKILL.md b/.claude/skills/sync-git/SKILL.md new file mode 100644 index 0000000..b964898 --- /dev/null +++ b/.claude/skills/sync-git/SKILL.md @@ -0,0 +1,8 @@ +--- +name: sync-git +description: Sync local repo with upstream, clean up branches and remotes +disable-model-invocation: true +allowed-tools: Bash +--- + +Run `bash scripts/synch-git.sh` and report the output to the user. diff --git a/scripts/synch-git.sh b/scripts/synch-git.sh new file mode 100644 index 0000000..a4e00b6 --- /dev/null +++ b/scripts/synch-git.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "=== Syncing main with upstream ===" +git fetch upstream main +git checkout main +git merge upstream/main --ff-only + +echo "" +echo "=== Pruning stale remote-tracking references ===" +git fetch origin --prune +git fetch upstream --prune + +echo "" +echo "=== Deleting local branches merged into main ===" +merged=$(git branch --merged main | grep -v '^\*\|main' || true) +if [ -n "$merged" ]; then + echo "$merged" | xargs git branch -d +else + echo "No merged branches to delete." +fi + +echo "" +echo "=== Done ===" +git branch