Skip to content

generic-automation-and-it/smooth-ai-stockanalysis / .agents/skills/git-sync

git-sync

Verified

Sync the current working branch with origin/main and optionally resolve merge conflicts. Use when synchronizing local branch with the latest changes from main, with automatic or manual conflict resolution.

FileKindSize
AGENTS.mdmarkdown753 B
SKILL.mdskill md4.0 KB
agents/openai.yamlconfig300 B
scripts/safe-sync.shexecutablescript1.6 KB

scripts/safe-sync.sh

View on GitHub
#!/usr/bin/env bash
# git-sync — fetch origin/main and merge into the current branch.
#
# Performs the deterministic part of both modes:
#   - fetches origin/main and merges (non-interactively, --no-edit)
#   - on clean merge:    prints "MERGE_OK" then the last 5 commits
#   - on conflict:       prints "MERGE_CONFLICTS" then the unmerged files,
#                        LEAVING the conflicts in the working tree
#   - on other failure:  prints "MERGE_ERROR" (dirty tree, missing ref, hook
#                        failure, etc. — NOT a content conflict)
#
# Mode 1 (safe): the agent reports the conflicts and stops.
# Mode 2 (--fix): the agent resolves the conflicts left in the tree, stages, commits.
# Either way the merge decision/resolution stays with the agent; this script only
# does the fetch+merge plumbing. Exit code: 0 clean merge, 1 conflict, 2 other error.
#
# Usage: safe-sync.sh [base-ref]   (default base-ref: origin/main)
set -euo pipefail

BASE_REF="${1:-origin/main}"
REMOTE="${BASE_REF%%/*}"
BRANCH="${BASE_REF#*/}"

# Fetch failures (missing remote/ref, network) are non-merge errors — keep the
# MERGE_OK/MERGE_CONFLICTS/MERGE_ERROR contract intact rather than dying via set -e.
if ! git fetch "$REMOTE" "$BRANCH"; then
  echo "MERGE_ERROR"
  exit 2
fi

if git merge --no-edit "$BASE_REF"; then
  echo "MERGE_OK"
  git log --oneline -5
  exit 0
else
  CONFLICTS="$(git diff --name-only --diff-filter=U)"
  if [ -n "$CONFLICTS" ]; then
    echo "MERGE_CONFLICTS"
    printf '%s\n' "$CONFLICTS"
    exit 1
  fi
  # Non-conflict failure: dirty working tree, missing ref, failing hook, etc.
  echo "MERGE_ERROR"
  exit 2
fi
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall