Return to Video

Rebase • GitHub & Git Foundations

  • 0:00 - 0:03
    Git Rebase is the ability
    to take existing commits,
  • 0:03 - 0:07
    and to place them on a branch
    that starts today.
  • 0:07 - 0:09
    ♪ (jazzy theme music throughout) ♪
  • 0:12 - 0:15
    Creating a branch is a tough decision.
  • 0:15 - 0:17
    Start it today, or start it later?
  • 0:17 - 0:21
    Well, some important fixes
    might be happening right now.
  • 0:21 - 0:23
    So better wait until tomorrow.
  • 0:23 - 0:26
    That difficult decision
    has gone away with Git.
  • 0:26 - 0:28
    Start a branch whenever you like,
  • 0:28 - 0:31
    and make it contain the changes
    that you intend to deliver.
  • 0:32 - 0:33
    Focused on a particular feature,
  • 0:34 - 0:36
    bug fix, or objective.
  • 0:39 - 0:41
    What about wanting this to start
  • 0:41 - 0:42
    at a later place in history,
  • 0:42 - 0:45
    in order to incorporate those hot fixes
  • 0:45 - 0:46
    that are going on
    to the master branch?
  • 0:47 - 0:50
    No problem.
    Rebase to the rescue.
  • 0:50 - 0:53
    Rebase, in its standard usage form,
  • 0:53 - 0:58
    allows one branch to be relocated
    farther down the history track,
  • 0:58 - 1:03
    meaning taking all of the changes
    that are isolated on your branch
  • 1:03 - 1:06
    and acting as if they happened after
  • 1:06 - 1:08
    all of the modern work
    on the master branch.
  • 1:09 - 1:11
    This accomplishes the same thing,
  • 1:11 - 1:15
    but with cleaner history
    than doing a reverse merge
  • 1:15 - 1:17
    from the master branch
    to the feature branch.
  • 1:18 - 1:20
    The same contents will be present
    in the feature branch,
  • 1:21 - 1:24
    but without the complication of the merge
  • 1:24 - 1:27
    going into that feature branch,
    and recorded in its history.
  • 1:30 - 1:32
    It's important to note
    that the rebase command
  • 1:32 - 1:35
    is altering all of the commits
    present in the branch.
  • 1:36 - 1:38
    It's preserving all of the work you did,
  • 1:38 - 1:41
    but their location and relationship
    to other commits
  • 1:41 - 1:43
    is all changing.
  • 1:43 - 1:46
    This is primarily used for a branch
    that you only own,
  • 1:46 - 1:49
    and isn't being worked on by others.
  • 1:49 - 1:50
    The change in the relationship
  • 1:50 - 1:52
    and identifier for each of those commits,
  • 1:52 - 1:55
    makes it difficult to reconcile
    with the work of others.
  • 1:56 - 2:00
    We're primarily talking about a branch
    that you are focused on.
  • 2:00 - 2:04
    But with those constraints in place,
    the use is quite simple.
  • 2:04 - 2:07
    Git checkout to the feature branch,
  • 2:08 - 2:12
    git rebase on the source branch,
    typically master.
  • 2:13 - 2:15
    That will then iteratively walk through
  • 2:15 - 2:18
    all of the commits that have happened
    on the feature branch,
  • 2:18 - 2:23
    and replay them as if they were being
    robotically rewritten,
  • 2:23 - 2:28
    starting from the latest point in time
    on the master branch.
  • 2:28 - 2:30
    When the process completes,
  • 2:30 - 2:33
    after seeing it step through
    all of the individual commits,
  • 2:33 - 2:36
    it will let you know that
    the rebase is complete,
  • 2:36 - 2:38
    and you'll return
    to the command prompt
  • 2:38 - 2:40
    in what appears to be a similar state
  • 2:40 - 2:42
    to before you ran that instruction.
  • 2:43 - 2:47
    However, all of those historical commits
    now have new identifiers,
  • 2:47 - 2:49
    keep that in mind.
  • 2:49 - 2:51
    You'll find a request to use this pattern
  • 2:51 - 2:53
    is most common in open source projects.
  • 2:54 - 2:56
    It's because they want to optimize
  • 2:56 - 2:58
    for future readership of the code base.
  • 2:58 - 3:02
    A single straight line of history
    provides the easiest reading
  • 3:02 - 3:05
    for a future contributor to this project.
  • 3:05 - 3:07
    This is why they put the burden
    on the contributors,
  • 3:07 - 3:09
    to make the history clean.
  • 3:09 - 3:11
    It's an effort, but one that benefits
  • 3:11 - 3:14
    every future collaborator
    on this project.
  • 3:17 - 3:19
    Continuously delivered applications,
  • 3:19 - 3:21
    such as web services, and web apps,
  • 3:22 - 3:26
    are optimized, generally,
    for merges, not rebase.
  • 3:26 - 3:29
    They want the quickest possible
    delivery mechanism
  • 3:29 - 3:33
    to send a change, small and focused,
    into the master branch.
  • 3:34 - 3:36
    If that doesn't do
    everything that it should,
  • 3:36 - 3:40
    another branch is worked on,
    and merged back in again.
  • 3:40 - 3:42
    Rebase is a powerful feature
  • 3:42 - 3:44
    that lets you optimize
    for clarity of history.
  • 3:44 - 3:47
    Just bear in mind the needs
    of your project and your team.
  • 3:48 - 3:50
    If it is for quick delivery
    of feature branches,
  • 3:50 - 3:52
    just merge them in.
  • 3:52 - 3:55
    If it's for clarity of history,
    engage in using Rebase.
  • 3:57 - 3:59
    Thanks for watching this
    Git & GitHub Foundations
  • 3:59 - 4:00
    episode on Rebase.
  • 4:01 - 4:03
    Be sure to subscribe
    to our channel, over here,
  • 4:03 - 4:05
    ask us questions or comments
    in the box below,
  • 4:05 - 4:09
    or watch one of the related episodes,
    such as on creating a branch.
Title:
Rebase • GitHub & Git Foundations
Video Language:
English
Team:
GitHub
Project:
Git and GitHub Foundations
Duration:
04:21
There has been no activity on this language so far.

English subtitles

Revisions Compare revisions