Rebasing vs Merging & Squashing
Rebasing moves or combines a sequence of commits to a new base commit, generating a cleaner linear commit history list.
1 Rebase Commands
Shell — Rebasing CLI
# Rebase active feature branch onto main
git checkout feature-login
git rebase main
# Interactive rebase (squash multiple commits into a single commit)
git rebase -i HEAD~3
Warning: Never rebase commits that have been pushed to public remote repositories, as it rewrites history and breaks other developers workspaces.
2 Code Challenge
Challenge: Create three trivial commits in a feature branch, run an interactive rebase (
rebase -i), and squash the last two commits into the first one.