git rebase
Reapply commits from your current branch onto another base
Practical example
git checkout feature-login git rebase main # Replays feature commits on top of main # For interactive: git rebase -i HEAD~3 # To abort a bad rebase: git rebase --abort
Command overview & how it works
Rewrites commit history by taking commits from your branch and replaying them one by one on top of another branch. The result is a linear history — it looks like all work was done sequentially on the same branch. Use git rebase main while on a feature branch to incorporate the latest main changes without creating a merge commit. Use git rebase -i (interactive rebase) to squash, reorder, edit, or drop commits — a powerful tool for cleaning up history before sharing it. Use git rebase --onto to move a range of commits to a completely different parent. The golden rule of rebasing: never rebase commits that have been pushed to a shared branch or that others have based work on. Rebase rewrites commit hashes, so force-pushing a rebased branch disrupts collaborators.
Resolve conflicts and master branch mechanics
Understand 3-way diffs, conflict marker anatomy, and rebasing playbooks in the 97-page offline course — ₹499.
Practical tips
- Never rebase commits that others have already pulled — it rewrites hashes and breaks their history.
- Use git rebase -i HEAD~n to squash, reword, reorder, or drop recent commits before pushing them.
- If a rebase goes sideways, git rebase --abort restores your branch to its pre-rebase state.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git rebase
- Guide
Git Branching Strategies: Git Flow vs Trunk-Based Development
Compare the most popular branching models and learn when to use merge, rebase, and squash for a clean project history.
8 min readRead guide - Guide
Git Rebase vs Merge: When to Use Each
A clear breakdown of the trade-offs between rebasing and merging, with examples of when each approach makes sense.
5 min readRead guide - Guide
Resolving Git Merge Conflicts: A Practical Guide
Conflicts are inevitable. Learn how to read conflict markers, resolve them systematically, and use tools to make merging painless.
6 min readRead guide
Related commands
More from Branching & Merging