-
Not Synced
Git Rebase is the ability
to take existing commits,
-
Not Synced
and to place them on a branch
that starts today.
-
Not Synced
♪ (jazzy theme music throughout) ♪
-
Not Synced
Creating a branch is a tough decision.
-
Not Synced
Start it today, or start it later?
-
Not Synced
Well, some important fixes
might be happening right now.
-
Not Synced
So better wait until tomorrow.
-
Not Synced
That difficult decision
has gone away with Git.
-
Not Synced
Start a branch whenever you like,
-
Not Synced
and make it contain the changes
that you intend to deliver.
-
Not Synced
Focused on a particular feature,
-
Not Synced
bug fix, or objective.
-
Not Synced
What about wanting this to start
-
Not Synced
at a later place in history,
-
Not Synced
in order to incorporate those hot fixes
-
Not Synced
that are going on to the master branch?
-
Not Synced
No problem.
Rebase to the rescue.
-
Not Synced
Rebase, in its standard usage form,
-
Not Synced
allows one branch to be relocated
farther down the history track,
-
Not Synced
meaning taking all of the changes
that are isolated on your branch,
-
Not Synced
and acting as if they happened after
-
Not Synced
all of the modern work
on the master branch.
-
Not Synced
This accomplishes the same thing,
but with cleaner history,
-
Not Synced
than doing a reverse merge
-
Not Synced
from the master branch
to the feature branch.
-
Not Synced
The same contents will be present
in the feature branch,
-
Not Synced
but without the complication of the merge,
-
Not Synced
going into that feature branch,
and recorded in its history.
-
Not Synced
It's important to note
that the rebase command
-
Not Synced
is altering all of the commits
present in the branch.
-
Not Synced
It's preserving all of the work you did,
-
Not Synced
but their location and relationship
to other commits
-
Not Synced
is all changing.
-
Not Synced
This is primarily used for a branch
that you only own,
-
Not Synced
and isn't being worked on by others.
-
Not Synced
The change in the relationship,
-
Not Synced
and identifier for each of those commits,
-
Not Synced
makes it difficult to reconcile
with the work of others.
-
Not Synced
We're primarily talking about a branch
that you are focused on.
-
Not Synced
But with those constraints in place,
the use is quite simple.
-
Not Synced
git checkout to the feature branch,
-
Not Synced
git rebase on the source branch,
typically master.
-
Not Synced
That will then iteratively walk through
all of the commits
-
Not Synced
that have happened on the feature branch,
-
Not Synced
and replay them as if they were being
robotically rewritten,
-
Not Synced
starting from the latest point in time
on the master branch.
-
Not Synced
When the process completes,
-
Not Synced
after seeing it step through all of the individual commits,
-
Not Synced
it will let you know that the rebase is complete,
-
Not Synced
and you'll return to the command prompt
-
Not Synced
and what appears to be a similar state
-
Not Synced
to before you ran that instruction.
-
Not Synced
However, all of those historical commits
now have new identifiers,
-
Not Synced
keep that in mind.
-
Not Synced
You'll find a request to use this pattern
-
Not Synced
is most common in open source projects.
-
Not Synced
It's because they want to optimize
-
Not Synced
for future readership of the code base.
-
Not Synced
A single straight line of history
provides the easiest reading
-
Not Synced
for a future contributor to this project.
-
Not Synced
This is why they put the burden
on the contributors,
-
Not Synced
to make the history clean.
-
Not Synced
It's an effort, but one that benefits
-
Not Synced
every future collaborator on this project.
-
Not Synced
Continuously delivered applications,
-
Not Synced
such as web services, and web apps,