Git Rebase
Replay commits onto a new base for a linear, review-friendly history.
- git rebase
- interactive rebase
- git pull rebase
- rebase conflict
- squash commits
Git Rebase
Replay commits onto a new base for a linear, review-friendly history.
Commands
| Command | What it does |
|---|---|
git rebase main | Replay current branch on top of main |
git rebase -i HEAD~3 | Interactively reword, squash, or drop 3 commits |
git rebase --continue | Resume after resolving conflicts |
git rebase --abort | Cancel and return to the pre-rebase state |
git pull --rebase | Fetch and rebase instead of merging |
Example
git switch feature/search
git rebase main
git rebase -i HEAD~2 # squash fixups
FAQ
Rebase or merge?
Rebase private feature branches for linear history; merge shared branches (main) to avoid rewriting public history.
Is rebasing pushed commits safe?
Only if no one else builds on them; otherwise it duplicates commits for collaborators.
Частые вопросы
Rebase or merge?
Rebase private feature branches for linear history; merge shared branches (main) to avoid rewriting public history.
Is rebasing pushed commits safe?
Only if no one else builds on them; otherwise it duplicates commits for collaborators.
Git
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Add and Commit
Stage changes and record them as commits with clear messages.
Git Branch Basics
Create, list, rename, and delete branches for parallel work.