$30 off During Our Annual Pro Sale. View Details »

A Rebasing Workflow for Git

A Rebasing Workflow for Git

You've decided to level up your Git skills and have heard that rebasing is where it's at. In this session we'll talk about: WHY rebasing can make it easier to untangle your project's history; WHEN you should use rebase; WHAT rebasing actually does to your repository; and HOW it actually looks when things go right (and how to recover when things go wrong).

Emma Jane Hogbin Westby

February 18, 2015
Tweet

More Decks by Emma Jane Hogbin Westby

Other Decks in Technology

Transcript

  1. A Rebasing Workflow
    Emma Jane Hogbin Westby - Trillium Consultancy Ltd.
    www.gitforteams.com
    https://speakerdeck.com/emmajane/a-rebasing-workflow-for-git
    @emmajanehw

    View Slide

  2. A Rebasing Workflow
    Emma Jane Hogbin Westby - Trillium Consultancy Ltd.
    www.gitforteams.com
    https://speakerdeck.com/emmajane/a-rebasing-workflow-for-git
    @emmajanehw

    View Slide

  3. A Rebasing Workflow
    Emma Jane Hogbin Westby - Trillium Consultancy Ltd.
    www.gitforteams.com
    https://speakerdeck.com/emmajane/a-rebasing-workflow-for-git
    @emmajanehw

    View Slide

  4. Agenda
    • the tl;dl
    • Rant: why I don't like rebasing
    • Rave: when / why I use rebase
    • Wrap-up
    • Q&A

    View Slide

  5. the tl;dl
    too long; didn't listen

    View Slide

  6. Why should I rebase?
    • Because it makes your commit history easier to
    read, and manipulate.
    • “Because Joe told me to.”

    View Slide

  7. Rebasing is like

    a malleable sports re-play.
    Step 1. Rewind the history of your branch.
    Step 2. Apply new commits from an outside
    source.
    Step 3. Then re-apply your work.

    View Slide

  8. Rebasing is like

    a malleable sports re-play.
    Step 1. Rewind the history of your branch.
    Step 2. Apply new commits from an outside
    source.
    Step 3. Then re-apply your work.

    View Slide

  9. Rebasing is like

    a malleable sports re-play.
    Step 1. Rewind the history of your branch.
    Step 2. Apply new commits from an outside
    source.
    Step 3. Then re-apply your work.

    View Slide

  10. Rebasing is like

    a malleable sports re-play.
    Step 1. Rewind the history of your branch.
    Step 2. Apply new commits from an outside
    source.
    Step 3. Then re-apply your work.

    View Slide

  11. When should I rebase?

    View Slide

  12. When should I rebase?
    • Before sharing proposed
    work.

    View Slide

  13. When should I rebase?
    • Before sharing proposed
    work.

    View Slide

  14. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.

    View Slide

  15. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.

    View Slide

  16. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.
    • To split a commit into two.

    View Slide

  17. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.
    • To split a commit into two.

    View Slide

  18. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.
    • To split a commit into two.
    $ git rebase -i edit

    View Slide

  19. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.
    • To split a commit into two.
    $ git rebase -i edit
    rebase -i squash

    View Slide

  20. When should I rebase?
    • Before sharing proposed
    work.
    • To update your local working
    branch.
    • To split a commit into two.
    $ git rebase -i edit
    rebase -i squash
    rebase

    View Slide

  21. How do I rebase?
    • Squash a bunch of tiny commits into one:
    $ git rebase --interactive
    • Bring your local, working branch up-to-date
    $ git pull master
    $ git checkout my_local_branch
    $ git rebase master

    View Slide

  22. Groundhog Day Conflict?!
    • Resolve the conflict and then immediately save your
    recorded solution with:
    $ git rerere
    • Proactively turn on REuse REcorded REsolution:
    $ git config --global rerere.enabled true
    • Bad merge? Git will remember the wrong resolution.
    Immediately forget how you resolved it with:
    $ git rerere forget

    View Slide

  23. How do I stop rebasing?
    • If things go right, it will stop on its own.
    • If there are tears, you can abort.
    $ git rebase --abort

    View Slide


  24. let the rants begin!

    View Slide

  25. Rant
    Why I don’t like rebasing.

    View Slide

  26. Historical Revisionism

    View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. Rave
    Why I love the effects of rebasing.

    View Slide

  32. Making Whole
    Thoughts

    View Slide

  33. Resources for

    Good Commit Messages
    gitforteams.com/resources/commit-granularity.html

    View Slide

  34. Converting Conversations
    to Conclusions

    View Slide

  35. Patches vs.
    Pull Requests

    View Slide

  36. Merge vs. Rebase

    View Slide

  37. Often drawing the history graph
    BEFORE running a command
    will help you
    choose the right command.

    View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. Choosing a Strategy
    • Pull = Fetch + Merge
    • Merge -> no fast forward (“true merge”)
    • Merge -> with fast forward
    • Merge with --squash -> all into one
    • Rebase -> rewind + replay
    • Cherry Pick -> copy and paste commits

    View Slide

  42. In Summary
    • The benefits of rebasing are most apparent to projects
    with multiple branches and multiple committers.
    • Rebasing allows you to reshape commit history so that
    you are storing conclusions, not conversations.
    • Rebasing can be used in place of merge to update a
    branch and results in a simplified graph of your
    repository history.
    • Rebasing can be used interactively to reshape a
    series of commits.

    View Slide

  43. www.gitforteams.com
    Emma Jane Hogbin Westby
    https://speakerdeck.com/emmajane/a-rebasing-workflow-for-git
    @emmajanehw

    View Slide