Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git workshop

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Git workshop

Avatar for Tom de Bruijn

Tom de Bruijn

October 30, 2020
Tweet

More Decks by Tom de Bruijn

Other Decks in Programming

Transcript

  1. @tombruijn Goal of workshop • Introduction to rebasing • Why

    rebase? • Explain how to rebase • Encourage you to rebase more
  2. @tombruijn Don't be afraid of Git! We can restore things

    Things don't disappear never to be seen again
  3. @tombruijn Why rebase? • Updating branches on other branches •

    Include other people's bug fixes in your branch • Alternative to a merge commit
  4. @tombruijn Why rebase? • Fixing small issues in previous commits

    • Squash your own bug and test fixes • Updating in commit messages • Fixing typos • Adding more content
  5. @tombruijn Why a readable history? • We do this for

    our team • We do this for our future selves From: Git is about communication presentation
  6. @tombruijn ✅ Better communication • git blame, git log ✅

    Better reviews ✅ Faster reviews ✅ Faster debugging From: Git is about communication presentation
  7. @tombruijn Not a deep dive • Not a tutorial on

    how to write commit messages • Want to learn more about communication in git? • tomdebruijn.com/posts/git-is-about-communication/ Blog post and #NoRuKo talk
  8. @tombruijn Rebasing on another branch Rebasing on the branch we

    branched off from Get the latest bug fixes and features
  9. @tombruijn Rebasing goal • Rebase feature branch on main branch

    • To include bug fixes in our branch • Prevent merge conflicts when merging our feature branch ✅
  10. @tombruijn The next day you realize you better refactor the

    button component making it easier to use
  11. @tombruijn Rebasing goal • Tidy up our branch for review

    • Make it easier to review for our team • The merged result is readable 3+ months from now ✅
  12. @tombruijn Git history • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests Older Newer
  13. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • How would you present your commits? How to clean up this branch?
  14. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • WIP • Add button to user profile page • Refactor button component • Fix tests Reduce noise commits: merge commits
  15. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • Add button to user profile page • Refactor button component • Fix tests Reduce noise commits: WIP commits
  16. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • Add button to user profile page • Refactor button component Squash "Fix" commits with the commits that broke things in the first place
  17. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • Add button to user profile page • Refactor button component • Rewrite user profile page button Does the refactor commit also include a rewrite of the first commit?
  18. @tombruijn Before After • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests • Refactor button component - PR #1 • Add button to user profile page - PR #2 More readable history. No double implementation of the button Send in the refactor PR first so your team can start reviewing it already
  19. @tombruijn Interactive rebase options • pick • Keep commit for

    rebasing. (Default option) • drop • Remove commit from history. Delete it. • reword • Update commit message. • edit • Edit commit and message. Split commits. • Reordering commits • Change lines to reorder commits
  20. @tombruijn Squashing Merge two commits together and keep their messages.

    Used for: • merging WIP work across commits
  21. @tombruijn Fixup Merge two commits together, only keep the first

    message. Used for: • typos • test fixes
  22. @tombruijn Abort? Abort!! • git rebase --abort • Run into

    merge conflicts and don't know how to solve? Abort! • (Revert changes you made during the rebase) ❌
  23. @tombruijn Backup branches • git checkout -b backup-branch • git

    checkout - # Go to previous branch • # Rebase • # If it did not go well? • git checkout backup-branch
  24. @tombruijn git reflog • git reflog • Ref[erence] log •

    See all your actions in git • In a semi-human-readable format
  25. @tombruijn git fixup • What are "fixup!" commits? • Mark

    commits as fixup commits for future rebasing • So you don't need to rebase now
  26. @tombruijn • We do this for our team • We

    do this for our future selves From: Git is about communication presentation
  27. @tombruijn ✅ Better communication ✅ Better reviews ✅ Faster reviews

    ✅ Faster debugging From: Git is about communication presentation
  28. @tombruijn Leave better reviews • Ask questions if you have

    any! • Worst case you learn something new
  29. @tombruijn Review questions • Why is the change necessary? What's

    the problem? • Why was this solution chosen? • What alternative solutions were available? • Would anyone understand this 3 months from now? ❓
  30. @tombruijn In a perfect world • Be able to understand

    what the MR is about, using only the MR contents • You need the whole team to work together for this!
  31. @tombruijn Test the code • Check out the MR locally

    and test the changes • Click through the app / run the app • Verify if the change actually works • Verify if the tests actually test the changed logic