Home

Rebase

Rebase is an operation in version control systems that moves or reorganizes a sequence of commits to a new base commit. In Git, rebase works by reapplying the commits of one branch on top of another branch, producing new commits with different identifiers. The effect is a linear history where the feature branch appears to have been created from the tip of the base branch.

If you want to move a branch to start from another base, you run git rebase <upstream>

Interactive rebasing, invoked as git rebase -i, offers editing, reordering, squashing, rewording, or removing commits. It

Rebase vs merge: Rebase rewrites history and avoids creating merge commits, while merge preserves the exact

Best practices: use rebase on private or feature branches, keep main branches intact, and coordinate with teammates

while
on
the
branch
to
be
rewritten.
Git
determines
the
common
ancestor,
resets
the
branch
to
the
target
base,
and
replays
each
commit
from
the
original
branch.
The
result
is
a
linear
sequence
of
commits;
you
can
adjust
behavior
with
options
such
as
--onto
and
related
forms.
is
commonly
used
to
tidy
a
set
of
commits
before
sharing
or
merging,
for
example
by
combining
small
fixes
into
a
single
commit
or
improving
commit
messages.
history
and
creates
a
merge
commit.
Rewriting
public
history
can
disrupt
collaborators
and
may
require
force
pushes
to
update
remote
branches.
before
rebasing
shared
history.
If
a
branch
has
already
been
published,
consider
merging
instead,
or
obtain
consensus
to
rebase
and
use
git
push
--force-with-lease
to
update
the
remote
branch
safely.