Fetches from origin and integrates changes from a source branch. Automatically chooses rebase (for unpushed branches) or merge (for pushed branches) strategy.
Usage
/bkff:git-sync [source-branch]
Strategy Selection
Condition
Strategy
Branch not pushed to origin
Rebase (clean history)
Branch already pushed to origin
Merge (preserve history)
Example Output
## Sync Complete (Rebase)
### Fetch
- ✓ Fetched from origin
### Strategy
- **Mode**: Rebase (branch not yet pushed)
- **Source**: main
### Result
- **Status**: Up to date with main
Requirements
Must be run inside a git worktree
git CLI with rerere enabled recommended
No uncommitted changes
Implementation
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"
source "$PLUGIN_DIR/lib/common.sh"
source "$PLUGIN_DIR/lib/git-helpers.sh"
require_worktree
SOURCE_BRANCH="${1:-$(get_main_branch)}"
CURRENT_BRANCH=$(get_current_branch)
# Check for uncommitted changes
if has_changes; then
error_exit "You have uncommitted changes. Commit or stash before syncing."
fi
# Prevent syncing main onto itself
if [[ "$CURRENT_BRANCH" == "$SOURCE_BRANCH" ]]; then
error_exit "Already on $SOURCE_BRANCH. Nothing to sync."
fi
echo "## Sync Process"
echo ""
# FR-018: Fetch from origin
echo "### Fetch"
info "Fetching from origin..."
if git fetch origin --prune; then
echo "- ✓ Fetched from origin"
else
error_exit "Fetch failed. Check network connection."
fi
echo ""
# Verify source branch exists
if ! git rev-parse --verify "origin/$SOURCE_BRANCH" &>/dev/null; then
error_exit "Branch '$SOURCE_BRANCH' not found on origin."
fi
# FR-019: Determine if branch has been pushed
echo "### Strategy"
if is_branch_pushed "$CURRENT_BRANCH"; then
STRATEGY="merge"
echo "- **Mode**: Merge (branch already pushed to origin)"
else
STRATEGY="rebase"
echo "- **Mode**: Rebase (branch not yet pushed)"
fi
echo "- **Source**: $SOURCE_BRANCH"
echo "- **Target**: $CURRENT_BRANCH"
echo ""
# Enable rerere for conflict resolution
git config rerere.enabled true
# FR-020/FR-021: Execute strategy
echo "### Result"
if [[ "$STRATEGY" == "rebase" ]]; then
# FR-020: Rebase for unpushed branches
info "Rebasing onto origin/$SOURCE_BRANCH..."
if git rebase "origin/$SOURCE_BRANCH"; then
COMMITS=$(git rev-list --count "origin/$SOURCE_BRANCH..HEAD" 2>/dev/null || echo "0")
echo "- **Commits rebased**: $COMMITS"
echo "- **Conflicts**: None"
echo "- **Status**: Up to date with $SOURCE_BRANCH"
echo ""
success "Branch rebased successfully. Ready to push."
else
echo "- **Status**: Conflicts require resolution"
echo ""
echo "### Conflicts"
git diff --name-only --diff-filter=U | while read -r file; do
echo "- $file"
done
echo ""
echo "### Next Steps"
echo "1. Resolve conflicts in the files above"
echo "2. Stage resolved files: git add <file>"
echo "3. Continue rebase: git rebase --continue"
echo ""
echo "Or abort: git rebase --abort"
exit 1
fi
else
# FR-021: Merge for pushed branches
info "Merging origin/$SOURCE_BRANCH..."
if git merge "origin/$SOURCE_BRANCH" -m "Merge $SOURCE_BRANCH into $CURRENT_BRANCH"; then
MERGE_HASH=$(git rev-parse --short HEAD)
echo "- **Merge commit**: $MERGE_HASH"
echo "- **Conflicts**: None"
echo "- **Status**: Up to date with $SOURCE_BRANCH"
echo ""
success "Branch merged successfully."
else
echo "- **Status**: Conflicts require resolution"
echo ""
echo "### Conflicts"
git diff --name-only --diff-filter=U | while read -r file; do
echo "- $file"
done
echo ""
echo "### Next Steps"
echo "1. Resolve conflicts in the files above"
echo "2. Stage resolved files: git add <file>"
echo "3. Complete merge: git commit"
echo ""
echo "Or abort: git merge --abort"
exit 1
fi
fi
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: kbrockhoff-brockhoff-tools-claude-git-sync3description: Sync with Remote4---56# Sync with Remote78Fetches from origin and integrates changes from a source branch. Automatically chooses rebase (for unpushed branches) or merge (for pushed branches) strategy.910## Usage1112```13/bkff:git-sync [source-branch]14```1516## Strategy Selection1718| Condition | Strategy |19|-----------|----------|20| Branch not pushed to origin | Rebase (clean history) |21| Branch already pushed to origin | Merge (preserve history) |2223## Example Output2425```26## Sync Complete (Rebase)2728### Fetch29- ✓ Fetched from origin3031### Strategy32- **Mode**: Rebase (branch not yet pushed)33- **Source**: main3435### Result36- **Status**: Up to date with main37```3839## Requirements4041- Must be run inside a git worktree42- `git` CLI with rerere enabled recommended43- No uncommitted changes4445## Implementation4647```bash48#!/usr/bin/env bash49set -euo pipefail5051SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"52PLUGIN_DIR="$(dirname "$(dirname "$SCRIPT_DIR")")"53source "$PLUGIN_DIR/lib/common.sh"54source "$PLUGIN_DIR/lib/git-helpers.sh"5556require_worktree5758SOURCE_BRANCH="${1:-$(get_main_branch)}"59CURRENT_BRANCH=$(get_current_branch)6061# Check for uncommitted changes62if has_changes; then63 error_exit "You have uncommitted changes. Commit or stash before syncing."64fi6566# Prevent syncing main onto itself67if [[ "$CURRENT_BRANCH" == "$SOURCE_BRANCH" ]]; then68 error_exit "Already on $SOURCE_BRANCH. Nothing to sync."69fi7071echo "## Sync Process"72echo ""7374# FR-018: Fetch from origin75echo "### Fetch"76info "Fetching from origin..."77if git fetch origin --prune; then78 echo "- ✓ Fetched from origin"79else80 error_exit "Fetch failed. Check network connection."81fi82echo ""8384# Verify source branch exists85if ! git rev-parse --verify "origin/$SOURCE_BRANCH" &>/dev/null; then86 error_exit "Branch '$SOURCE_BRANCH' not found on origin."87fi8889# FR-019: Determine if branch has been pushed90echo "### Strategy"91if is_branch_pushed "$CURRENT_BRANCH"; then92 STRATEGY="merge"93 echo "- **Mode**: Merge (branch already pushed to origin)"94else95 STRATEGY="rebase"96 echo "- **Mode**: Rebase (branch not yet pushed)"97fi98echo "- **Source**: $SOURCE_BRANCH"99echo "- **Target**: $CURRENT_BRANCH"100echo ""101102# Enable rerere for conflict resolution103git config rerere.enabled true104105# FR-020/FR-021: Execute strategy106echo "### Result"107if [[ "$STRATEGY" == "rebase" ]]; then108 # FR-020: Rebase for unpushed branches109 info "Rebasing onto origin/$SOURCE_BRANCH..."110 if git rebase "origin/$SOURCE_BRANCH"; then111 COMMITS=$(git rev-list --count "origin/$SOURCE_BRANCH..HEAD" 2>/dev/null || echo "0")112 echo "- **Commits rebased**: $COMMITS"113 echo "- **Conflicts**: None"114 echo "- **Status**: Up to date with $SOURCE_BRANCH"115 echo ""116 success "Branch rebased successfully. Ready to push."117 else118 echo "- **Status**: Conflicts require resolution"119 echo ""120 echo "### Conflicts"121 git diff --name-only --diff-filter=U | while read -r file; do122 echo "- $file"123 done124 echo ""125 echo "### Next Steps"126 echo "1. Resolve conflicts in the files above"127 echo "2. Stage resolved files: git add <file>"128 echo "3. Continue rebase: git rebase --continue"129 echo ""130 echo "Or abort: git rebase --abort"131 exit 1132 fi133else134 # FR-021: Merge for pushed branches135 info "Merging origin/$SOURCE_BRANCH..."136 if git merge "origin/$SOURCE_BRANCH" -m "Merge $SOURCE_BRANCH into $CURRENT_BRANCH"; then137 MERGE_HASH=$(git rev-parse --short HEAD)138 echo "- **Merge commit**: $MERGE_HASH"139 echo "- **Conflicts**: None"140 echo "- **Status**: Up to date with $SOURCE_BRANCH"141 echo ""142 success "Branch merged successfully."143 else144 echo "- **Status**: Conflicts require resolution"145 echo ""146 echo "### Conflicts"147 git diff --name-only --diff-filter=U | while read -r file; do148 echo "- $file"149 done150 echo ""151 echo "### Next Steps"152 echo "1. Resolve conflicts in the files above"153 echo "2. Stage resolved files: git add <file>"154 echo "3. Complete merge: git commit"155 echo ""156 echo "Or abort: git merge --abort"157 exit 1158 fi159fi160```161162---163> Converted and distributed by [TomeVault](https://tomevault.io/claim/kbrockhoff) — claim your Tome and manage your conversions.164<!-- tomevault:4.0:skill_md:2026-04-14 -->
Run npx skillmds@latest add tomevault-io/kbrockhoff-brockhoff-tools-claude-git-sync in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Sync with Remote It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.