what is git rebase used for
Git rebase is used to move or replay your commits on top of another base commit, so your branch history looks linear and cleaner.
What it does
- It updates a feature branch so it starts from the latest main branch commit instead of an older one.
- It rewrites commit history by creating new commits, rather than adding a merge commit.
- It is often used before merging work, especially when you want a tidy history.
Why people use it
- To keep project history easy to read.
- To reduce noisy merge commits.
- To tidy up commits with interactive rebase, such as squashing, rewording, or dropping commits.
Simple example
If your branch was created from an older main, rebasing lets Git take your
commits and apply them again on top of the current main, which makes it look
like you started there in the first place.
One caution
Because rebase rewrites history, it is best used on local or private branches, not on branches other people are already using heavily.
TL;DR: use git rebase when you want a clean, linear commit history and you
are okay with rewriting your branch’s commits.