Performs interactive rebases with smart commit management and conflict resolution...
Helps perform safe, effective rebases with intelligent conflict detection and resolution guidance. Creates safety backups and provides step-by-step assistance through the entire rebase process.
Use Rebase when:
Use Merge when:
Best Practices:
--force-with-lease instead of --force# Simple rebase
git rebase <base-branch>
git rebase main
git rebase develop
# Interactive rebase
git rebase -i <base-branch>
git rebase -i HEAD~<n>
# Advanced rebase
git rebase --onto <new-base> <old-base> <branch>
git rebase -i --autosquash <base>
git rebase --rebase-merges <base>
git rebase -i --exec "npm test" <base>
# During rebase
git rebase --continue # After resolving conflicts
git rebase --abort # Cancel rebase
git rebase --skip # Skip current commit
# Force push (after rebase)
git push --force-with-lease # Safer (recommended)
git push --force-with-lease origin <branch>
git push --force # Dangerous
pick (p) - Use commit as-isreword (r) - Edit commit messageedit (e) - Stop for amendingsquash (s) - Combine with previous, keep both messagesfixup (f) - Combine with previous, discard this messagedrop (d) - Remove commitexec (x) - Run shell commandgit status # Check conflicted files
git diff # View conflicts
git checkout --theirs <file> # Accept their changes
git checkout --ours <file> # Accept our changes
git add <file> # Stage resolved file
git rebase --continue # Continue rebase
# Create backup before rebase
git branch backup/<branch-name>
# Restore from backup
git reset --hard backup/<branch-name>
# Find lost commits
git reflog
git reset --hard HEAD@{n}
git status # MUST be clean
git fetch origin # Get latest changes
git branch -vv # View branch info
Stop if: uncommitted changes exist (commit/stash first) or wrong branch
git branch backup/$(git branch --show-current)
git branch | grep backup # Verify created
develop (or main if no develop)mainmaingit diff <base-branch>...HEAD --check
git log --oneline --left-right --cherry-pick <base-branch>...HEAD
git rebase <base-branch> # Standard
git rebase -i <base-branch> # Interactive
Conflict markers:
<<<<<<< HEAD (yours)
Your changes
=======
Incoming changes
>>>>>>> base-branch
Resolve and continue:
# Edit files to resolve, then:
git add <resolved-files>
git rebase --continue
git status
git log --oneline -10
git push --force-with-lease origin $(git branch --show-current)
git branch -d backup/<branch-name> # Or -D to force
Accept theirs (base branch wins):
git checkout --theirs <file> && git add <file>
Accept ours (your changes win):
git checkout --ours <file> && git add <file>
Manual merge (combine both):
<<<<<<<, =======, >>>>>>>)git add <file>npm run lint && npm test && npm run build # JS/TS
python -m py_compile <file> && pytest # Python
cargo check && cargo test && cargo build # Rust
git fetch origin
git checkout feature/my-feature
git rebase origin/main
git push --force-with-lease
git rebase -i HEAD~5
# Change 'pick' to 'squash' for commits to combine
git rebase -i HEAD~3
# Change 'pick' to 'reword' for commits to rename
# Error: cannot rebase: You have unstaged changes
# Solution 1: Stash
git stash push -m "WIP before rebase" && git rebase main && git stash pop
# Solution 2: Commit
git add . && git commit -m "WIP" && git rebase main
git rebase --abort
git checkout correct-branch
git rebase main
# Resolve each conflict iteratively:
# 1. Edit files → 2. git add <files> → 3. git rebase --continue
# Repeat until complete
# Someone else pushed - coordinate with team first!
git fetch origin
git log origin/branch..HEAD # Review changes
git push --force-with-lease # Safe force push
# Abort current rebase
git rebase --abort
# Restore from backup
git reset --hard backup/<branch-name>
# Or find lost commits via reflog
git reflog
git reset --hard HEAD@{n}
# During development, create fixup commits
git commit --fixup=a1b2c3d
# Later, autosquash during rebase
git rebase -i --autosquash main
# Run tests after each commit
git rebase -i --exec "npm test" main
git rebase -i --exec "npm run lint && npm test" main
git rebase --rebase-merges main
git rebase <commit-hash>
git rebase -i <commit-hash>
git rebase --onto <new-base> <old-base> <branch>
gh pr checkout 123
git rebase main
git push --force-with-lease
# PR automatically updates
git mergetool
git config --global merge.tool vimdiff
| Issue | Solution |
|---|---|
| Rebase stuck/hanging | Check for editor input or conflict markers; git status; abort: git rebase --abort |
| Can't continue after resolving | Ensure all files staged: git add <files>; check for remaining conflict markers; git diff --check |
| Lost commits | git reflog → git reset --hard HEAD@{n} or restore from backup |
| Force push rejected | Use --force-with-lease; if fails, someone pushed → fetch and coordinate with team |
| Detached HEAD | git checkout -b recovery-branch or git checkout <branch-name> |
| Editor not opening | Set editor: git config --global core.editor "vim" or GIT_EDITOR=vim git rebase -i main |