Standard workflow for all rebase operations ('rebase branch', 'rebase on main', 'rebase onto'): replaces bash-based git rebase workflows with Git Safety Protocol—syncs base branch first, prevents mainline rebase errors, preserves working state, provides conflict resolution guidance. Canonical rebase implementation for git-workflows.
/plugin marketplace add cblecker/claude-skills/plugin install git-workflows@claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Use this skill for rebase requests: "rebase my branch", "rebase on main", "rebase onto X", "update my branch with main".
Use other skills for: syncing (syncing-branch for fetch+merge), viewing status (git status directly).
Rebases feature branch onto updated mainline, rewriting commit history. Handles state preservation, conflict resolution, optional author date reset.
Extract from user request: target branch (if specified, else mainline), author date preference ("keep dates"/"preserve dates" → preserve, default reset)
Objective: Verify environment is ready for rebase operation.
Step 1: Get current branch
Get current branch:
git branch --show-current
Capture: current_branch
Step 2: Check if on mainline
Run ../../scripts/get-mainline-branch.sh with the current branch as parameter
Parse JSON response:
mainline_branch fieldis_mainline flag (true if current branch matches mainline)Step 3: Check working tree status
Check status:
git status --porcelain
Capture: working tree clean status (empty = clean)
Validation Gate: Safe to Rebase
IF is_mainline = true: STOP immediately EXPLAIN: "Cannot rebase the mainline branch. Mainline should never be rebased as it's the stable reference point for all feature branches." INFORM: "Rebasing mainline would rewrite its history and break all feature branches based on it." PROPOSE: "Create a feature branch first if you need to test changes" EXIT workflow
IF is_mainline = false AND working tree not clean (status output not empty): INFORM: "Uncommitted changes detected - creating commit first" INVOKE: creating-commit skill WAIT for creating-commit to complete
IF creating-commit succeeded: VERIFY: Working tree is now clean PROCEED to Phase 2
IF creating-commit failed: STOP immediately EXPLAIN: "Cannot rebase without committing changes" EXIT workflow
IF is_mainline = false AND working tree clean: PROCEED to Phase 2
Save State: Store saved_branch = current_branch (preserve through all phases)
Phase 1 complete. Continue to Phase 2.
Objective: Identify which branch to rebase onto.
Step 1: Check user request for rebase target
Analyze user's request for target branch specification:
IF target branch specified in user request: Use specified branch as rebase base
IF no target branch mentioned: Use mainline_branch from Phase 1 as rebase base
Store rebase_base for later phases.
Phase 2 complete. Continue to Phase 3.
Objective: Switch to base branch for syncing.
Step 1: Checkout base branch
Checkout rebase base:
git checkout <rebase_base from Phase 2>
Error Handling
IF checkout succeeds: PROCEED to Phase 4
IF checkout fails: STOP immediately
Analyze and explain error:
"error: pathspec '...' did not match": Base branch doesn't exist locally
"error: Your local changes": Working tree not clean (shouldn't happen after Phase 1)
Other: Permission issues
Propose solution:
Doesn't exist: "Verify branch name with git branch --all or create it"
Permission: "Check repository access and file permissions"
WAIT for user decision
Phase 3 complete. Continue to Phase 4.
Objective: Ensure base branch is up-to-date with remote.
Plan Mode Handling
Plan mode is automatically enforced by the system. IF currently in plan mode:
Step 1: Invoke syncing-branch skill
INVOKE: syncing-branch skill WAIT for skill completion
Validation Gate: Sync Success
IF syncing-branch skill succeeded: INFORM: "Base branch synced successfully with remote" PROCEED to Phase 5
IF syncing-branch skill failed: STOP immediately EXPLAIN: "Failed to sync base branch with remote" SHOW: Error reported by syncing-branch skill PROPOSE solution: - "Check network connectivity" - "Review remote branch status" - "Retry sync operation" WAIT for user decision
Phase 4 complete. Continue to Phase 5.
Objective: Switch back to feature branch for rebase.
CRITICAL: Use Saved State
Retrieve saved_branch from Phase 1 (NOT current branch - we're on base branch now)
Step 1: Checkout feature branch
Checkout saved branch:
git checkout <saved_branch from Phase 1>
Error Handling
IF checkout succeeds: PROCEED to Phase 6
IF checkout fails: STOP immediately (CRITICAL FAILURE)
EXPLAIN: "Cannot return to feature branch - workflow interrupted mid-operation"
INFORM: "You are currently on base branch: <rebase_base from Phase 2>"
INFORM: "Your feature branch: <saved_branch from Phase 1>"
PROPOSE: "Manually checkout your feature branch with: git checkout <saved_branch>"
WORKFLOW FAILED - Manual intervention required
Phase 5 complete. Continue to Phase 6.
Objective: Perform the actual rebase operation.
Plan Mode: Auto-enforced read-only if active
Steps:
git rebase <rebase-base> (from Phase 2)Validation Gate:
git add, git rebase --continue or --abortNote: Conflicts are normal, not failures. Workflow PAUSED ≠ FAILED.
Continue to Phase 7.
Objective: Update author dates to current time.
Skip: IF user requested preserving dates
Plan Mode: Auto-enforced read-only if active
Steps:
git merge-base --fork-point <rebase-base> (from Phase 2)git rebase <fork-point> --reset-author-dateValidation Gate: IF reset fails:
Continue to Phase 8.
Objective: Confirm rebase completed successfully.
Steps:
Verify current branch:
git branch --show-current
Compare to saved_branch from Phase 1
Check status:
git status --porcelain
Verify clean (empty output)
Get recent commits:
git log --oneline -5
Report using template:
✓ Branch Rebased Successfully
**Branch:** <saved_branch> \
**Rebased onto:** <rebase_base> \
**Author dates:** <Reset|Preserved> \
**Working tree:** <Clean|Dirty>
**⚠ Important:** Force push required
Run: `git push --force-with-lease origin <saved_branch>`
Validation Gate: IF current branch ≠ saved_branch:
git checkout <saved_branch>"Workflow complete.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.