Get the FREE Ultimate OpenClaw Setup Guide →

sync

Scanned
npx machina-cli add skill YoniChechik/claude-code-config/sync --openclaw
Files (1)
SKILL.md
3.8 KB

Merges from origin/main, commits any local changes with professional message generation, and pushes to remote. This ensures the current branch is always ahead of (or equal to) origin/main, never behind or diverged.

Goal: Current branch HEAD >= origin/main (no divergence, no outdated commits)

What this means:

  • "Ahead" = local branch has commits that origin/main doesn't have yet
  • "Equal" = local branch is at the same commit as origin/main
  • "Behind/Diverged" = ❌ Never allowed - always merge first to stay current

Optional commit message hint from user input (can be empty string)

"$ARGUMENTS"

Process

Step 1: Fetch and Merge from Origin/Main

1.1: Fetch and Check State

git fetch origin
bash $HOME/.claude/scripts/git_branch_state.sh

Parse the JSON output. If behind_main is 0 and diverged is false, skip directly to Step 2 (no merge needed).

If behind_main > 0 or diverged is true, proceed with merge:

1.2: Execute Merge

git merge origin/main

1.3: Solve Conflicts (if any)

Git merge automatically:

  • Takes all non-conflicting changes from origin/main (newer code, new files, etc.)
  • Only creates conflicts where both branches modified the same lines

For conflicts, resolve by preferring current branch changes.

If conflicts occur:

  • Resolve them systematically
  • Stage the resolved files
  • Continue with the commit process

1.4: Merge Summary

After merge completes, provide brief summary:

  • What was merged: Source branch and commit range
  • Files added/modified/deleted: List key changes with file counts
  • Conflicts resolved: Detail any conflicts encountered and how they were resolved
  • Merge result: Success status

Result: Current branch now includes all commits from origin/main. The branch is either:

  • Equal to origin/main (if no local commits existed)
  • Ahead of origin/main (if local commits existed before merge)

This ensures we're never behind or diverged from origin/main.

Step 2: Analyze Changes for Commit Message

Review staged/unstaged changes to understand:

  • Type of change (add, fix, update, refactor)
  • Scope and impact
  • Key components modified Do this using git diff. Stage all unstaged changes.

Important: If changes exist, committing them (Step 6) will make the current branch ahead of origin/main. If no changes exist, skip to Step 8 - we're already synced.

Step 3: Check Plan Progress

If plan_*.md exists, review current phase status:

  • Identify which phase is being completed
  • Check if this represents a major milestone
  • Note any phase transitions

Step 4: Generate Professional Commit Message

Create structured commit message:

Format:

Brief description (50 chars max)

- Detailed bullet points of key changes
- Focus on WHY not just WHAT
- Reference phase completion if applicable

Step 5: Update Plan Status (if applicable)

If plan_*.md exists and phase completed:

  • Mark completed phase with ✓
  • Update status documentation

Step 6: Execute Commit

git commit -m "$(cat <<'EOF'
[Generated commit message]
EOF
)"

Step 7: Push to Remote

Push changes to remote repository:

git push

If this is the first push and the branch doesn't exist on remote yet:

git push -u origin HEAD

Result: After pushing, the current branch remains ahead of (or equal to) origin/main with all changes safely on remote.

Step 8: Verify Final State

bash $HOME/.claude/scripts/git_branch_state.sh

Parse the JSON output. Verify behind_main is 0 and diverged is false. If either check fails, report the issue to the user.

Step 9: Confirmation

Report commit hash, push status, and summary to user.

Final State: ✓ Current branch >= origin/main (ahead or equal, never behind or diverged)

Source

git clone https://github.com/YoniChechik/claude-code-config/blob/main/skills/sync/SKILL.mdView on GitHub

Overview

This skill keeps your feature branch up to date with origin/main by merging when needed, generating a professional commit for local changes, and pushing to the remote. It ensures the current HEAD is ahead of or equal to origin/main, avoiding divergence.

How This Skill Works

The process fetches origin, checks the branch state, and merges origin/main if behind or diverged. If conflicts occur, it guides resolution and then creates a structured commit message before pushing to the remote and validating that behind_main is 0 and diverged is false.

When to Use It

  • Before opening a pull request to ensure your feature branch is up to date with origin/main
  • After finishing local work to publish commits to the remote
  • When multiple teammates commit to origin/main and you need to stay aligned
  • If your local branch shows behind or diverged state from origin/main
  • When you want a professional, consistent commit message generated from your changes

Quick Start

  1. Step 1: git fetch origin && check state; if behind or diverged, git merge origin/main
  2. Step 2: Review staged/unstaged changes with git diff; if changes exist, generate a structured commit message and git commit
  3. Step 3: git push (or git push -u origin HEAD for first push) and verify with the state script

Best Practices

  • Always fetch origin before merging or reviewing changes
  • Resolve conflicts systematically and keep current branch changes as priority
  • Write a clear, structured commit message that explains why changes were made
  • Review plan_*.md status if present to reflect milestone progress
  • Verify final state with the provided script to ensure no divergence

Example Use Cases

  • Developer on feature/upgrade runs sync to incorporate latest origin/main and push a cohesive set of changes
  • Before creating a PR, a teammate uses sync to ensure the branch equals origin/main when no local changes exist
  • A bug fix is staged; sync generates a professional commit message and pushes it after merging origin/main
  • Several teammates commit to origin/main; you sync to keep your branch ahead and avoid merge conflicts later
  • You want a reliable, auditable commit history with why-not details included in the commit message

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers