‹ 首页

git-rebase-workflow

@skillforgeai-dev · 收录于 今天 · 上游提交 3 个月前

Guide Claude through safe git rebase workflows: interactive rebase, conflict resolution, squash strategies, and force-push safety. Use when the user asks "rebase my branch", "clean up commits", "squash commits before PR", "rebase onto main", "resolve rebase conflicts", or wants help with git history cleanup. 安全的 Git Rebase 工作流指南:交互式变基、冲突解决、 提交压缩策略和安全强制推送。

适合你,如果经常需要变基、压缩提交或解决 Git 冲突。

/ 通过 npx 安装 校验哈希
npx oh-my-skill add skillforgeai-dev/content-to-skill/git-rebase-workflow
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- skillforgeai-dev/content-to-skill/git-rebase-workflow
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify skillforgeai-dev/content-to-skill/git-rebase-workflow
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
0GitHub stars
~983最小装载
~983含声明引用
~2.3K文本包总量
索引托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · a5dd693

Git Rebase Workflow

Guide the user through safe, team-friendly git rebase operations — from syncing with main to interactive commit cleanup and safe force-pushing.

When to Use
  • User wants to rebase a feature branch onto main/develop
  • User needs to squash or clean up commits before a PR
  • User sees "branch has diverged" and needs guidance
  • User asks about interactive rebase (rebase -i)
  • User wants to set up rebase aliases or hooks
When NOT to Use
  • User is on main or a shared branch — warn them and suggest merge instead
  • User wants to rewrite history that has already been merged — this is destructive
  • User is resolving a complex merge and wants to preserve conflict resolution history
Prerequisites
  • Git installed (>= 2.0)
  • Working in a git repository with a remote
Step-by-Step Workflow
1. Assess the Situation
git status
git log --oneline -10
git rev-parse --abbrev-ref HEAD

Confirm the user is on a feature branch, not main. If on main, STOP and warn.

2. Sync with Upstream
git fetch origin
git rebase origin/main

If conflicts occur:

  1. Show the conflicted files: git diff --name-only --diff-filter=U
  2. Help resolve each conflict
  3. Stage resolved files: git add <file>
  4. Continue: git rebase --continue
  5. If unrecoverable: git rebase --abort
3. Interactive Rebase (Commit Cleanup)
git rebase -i origin/main

Apply these strategies:

  • squash WIP/typo/fix commits into their parent logical commit
  • reword vague messages like "updates" into descriptive ones
  • drop accidental commits (debug logs, temp files)
  • Keep logical boundaries: separate refactors from features from tests

Ordering: refactors first → features → tests → docs.

4. Force Push Safely
git push --force-with-lease

Never use --force — it can overwrite teammates' work. --force-with-lease fails safely if the remote has new commits you haven't seen.

If the push is rejected, fetch and rebase again before retrying.

5. Verify
git log --oneline origin/main..HEAD

Confirm:

  • Commits are in logical order
  • No WIP/fixup commits remain
  • Commit messages follow the team's convention
Input/Output Spec
  • Input: A git repository with a feature branch that needs rebasing or cleanup
  • Output: Clean, rebased branch with logical commits ready for PR review
Edge Cases & Error Handling

| Scenario | Action | |---|---| | On main branch | STOP — warn user, never rebase main | | Rebase conflicts in every commit | Consider git rebase --abort and doing a merge instead | | "diverged from origin" after rebase | Expected — verify with git log, then --force-with-lease | | Coworker pushed to same branch | Fetch first, discuss with coworker before force pushing | | Pre-push hook blocks push | Check if --force-with-lease is being blocked by policy |

Examples
Example 1: Clean up before PR

User: "I have 8 messy commits on my feature branch, help me clean up before opening a PR"

git fetch origin
git rebase -i origin/main
# In editor: squash WIP commits, reword vague ones
# Result: 3 clean commits — "add API endpoint", "add tests", "update docs"
git push --force-with-lease
Example 2: Sync stale branch

User: "My branch is 47 commits behind main"

git fetch origin
git rebase origin/main
# Resolve any conflicts one by one
git push --force-with-lease
# Branch is now up-to-date with clean linear history
Example 3: Recover from bad rebase

User: "I messed up a rebase and my branch looks wrong"

git reflog  # find the commit before rebase started
git reset --hard HEAD@{N}  # reset to pre-rebase state
# Now try again more carefully, or use merge instead
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。