Agent skill
auto-rebase
Rebase feature branches onto target, resolve conflicts, and keep PRs up-to-date with force-push
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/auto-rebase
SKILL.md
Skill: auto-rebase
What I do
Automate rebasing feature branches onto their target branch (typically next), resolving conflicts, and force-pushing to keep PRs current. Works with both regular branches and git worktrees.
When to use me
- PR shows "Not up to date" with target branch
- Before pushing review feedback fixes to avoid merge conflicts
- Before merging as a pre-merge checklist step
- After target branch has received new commits
- When CI fails due to branch divergence
Core principles
- Always rebase, never merge — Keep linear history.
- Use
--force-with-lease— Never bare--forceas this protects against overwriting others' pushes. - Rebase onto remote target — Always
git fetchfirst, then rebase ontoorigin/{target}rather than a local branch. - Worktree-aware — When using a bare repo with worktrees, fetch in the correct worktree context.
- Test after rebase — Always verify tests pass after rebasing before pushing.
Patterns & examples
Standard rebase workflow:
# Determine target branch from PR
TARGET=$(gh pr view {PR} --json baseRefName -q '.baseRefName')
# Fetch latest and rebase
git fetch origin $TARGET
git rebase origin/$TARGET
# Verify nothing broke
make test
make vet
# Force-push with lease (safe force)
git push --force-with-lease
Rebase with conflict resolution:
git fetch origin next
git rebase origin/next
# If conflicts occur:
# 1. Fix conflicts in affected files
# 2. Stage resolved files: git add <file>
# 3. Continue: git rebase --continue
# 4. If stuck: git rebase --abort (start over)
Worktree-specific rebase (bare repo setup):
# In a worktree like /home/user/Projects/Repo/feature-branch
git fetch origin next
git rebase origin/next
git push --force-with-lease
Automated rebase check (before push):
# Check if branch is behind target
BEHIND=$(git rev-list --count HEAD..origin/next)
if [ "$BEHIND" -gt "0" ]; then
echo "Branch is $BEHIND commits behind next — rebasing..."
git rebase origin/next
fi
Anti-patterns to avoid
- ❌
git merge origin/next— Creates merge commits and non-linear history. - ❌
git push --force— Can overwrite collaborator's pushes; use--force-with-lease. - ❌ Rebasing without fetching — Rebases onto a stale local branch.
- ❌ Pushing without testing after rebase — Rebase can introduce subtle failures.
- ❌ Rebasing shared/public branches (main, next) — Only rebase feature branches.
KB Reference
~/vaults/baphled/3. Resources/Knowledge Base/AI Development System/Skills/Git/Auto Rebase.md
Related skills
git-advanced— Advanced git operations including rebasinggit-master— Commit strategy and history managementcreate-pr— PR creation workflow that sets up clean branchespre-merge— Final validation that includes rebase checkrespond-to-review— Review response workflow that includes rebasing
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?