Agent skill
git-rebase-main
Safely rebase the current feature branch on top of the latest origin/main. Use when preparing a branch for PR, UAT, or release.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/git-rebase-main
SKILL.md
Git Rebase Main
Purpose
Ensure the current feature branch includes all the latest changes from main before proceeding with code review, UAT, or release. This prevents merge conflicts and ensures tests run against the latest codebase.
Hard Rules
Must
- Fetch from origin before rebasing.
- Handle rebase conflicts by stopping and reporting to the user.
- Verify the branch is not
mainbefore rebasing.
Must Not
- Force-push without user confirmation.
- Rebase if there are uncommitted changes.
Actions
1. Pre-flight Checks
# Ensure we're not on main
current_branch=$(git branch --show-current)
if [[ "$current_branch" == "main" ]]; then
echo "ERROR: Cannot rebase main onto itself. Switch to a feature branch first."
exit 1
fi
# Ensure working directory is clean
if [[ -n "$(git status --porcelain)" ]]; then
echo "ERROR: Working directory has uncommitted changes. Commit or stash them first."
exit 1
fi
2. Fetch and Rebase
git fetch origin
git rebase origin/main
3. Handle Conflicts
If the rebase fails due to conflicts:
- Report the conflicting files to the user.
- Do NOT attempt to auto-resolve.
- Wait for user to resolve and run
git rebase --continue.
4. Force Push (with confirmation)
After a successful rebase, the branch history has changed. Ask the user before force-pushing:
git push --force-with-lease origin HEAD
Golden Example
$ git fetch origin && git rebase origin/main
First, rewinding head to replay your work on top of it...
Applying: feat: add new formatting option
$ git push --force-with-lease origin HEAD
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?