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

Git workshop

Git workshop

590cc1623350bae67a2a10ff0f7f72de?s=128

Tom de Bruijn

October 30, 2020
Tweet

Transcript

  1. @tombruijn Git workshop Tom de Bruijn tomdebruijn.com

  2. @tombruijn Agenda • Why this workshop? • Git rebasing •

    Reviewing Pull/Merge Requests
  3. @tombruijn Interactive workshop That means you get to ask questions

    and do things
  4. @tombruijn This is a practical workshop Let's first discuss some

    theory And then apply it in practice
  5. @tombruijn Goal of workshop • Introduction to rebasing • Why

    rebase? • Explain how to rebase • Encourage you to rebase more
  6. @tombruijn Make notes! You know the best way to remember

    things In your own words
  7. @tombruijn Ask questions! Any time is good

  8. @tombruijn Questions so far? (This type of slide is also

    a hint for myself)
  9. @tombruijn Don't be afraid of Git! We can restore things

    Things don't disappear never to be seen again
  10. @tombruijn Rebasing Why? What? How? When?

  11. @tombruijn Why rebase? • Updating branches on other branches •

    Include other people's bug fixes in your branch • Alternative to a merge commit
  12. @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
  13. @tombruijn Commits to avoid • WIP • Fix test/bug •

    Merge commits • Instead, rebase
  14. @tombruijn In short: To create a more readable git history

  15. @tombruijn Questions so far?

  16. @tombruijn Why a readable history? • We do this for

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

    Better reviews ✅ Faster reviews ✅ Faster debugging From: Git is about communication presentation
  18. @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
  19. @tombruijn Rebasing on another branch Rebasing on the branch we

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

    • To include bug fixes in our branch • Prevent merge conflicts when merging our feature branch ✅
  21. @tombruijn A visual example Today we'll be using learngitbranching.js.org/?NODEMO

  22. @tombruijn Demo and questions? https:/ /github.com/tombruijn/rebase-workshop-example-1

  23. @tombruijn Feature branch rebasing How to tidy up a branch

    for review
  24. @tombruijn Imagine...

  25. @tombruijn You get assigned an issue to add a button

    to the user profile page
  26. @tombruijn At the end of the day you commit everything

    you have so far and sign off
  27. @tombruijn The next day you realize you better refactor the

    button component making it easier to use
  28. @tombruijn There was also a change on the main branch

    you needed to continue ⚠
  29. @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 ✅
  30. @tombruijn Questions so far? About our rebasing goals

  31. @tombruijn Git history • WIP • Add button • Merge

    branch "main" • Refactor button component • Fix tests Older Newer
  32. @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?
  33. @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
  34. @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
  35. @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
  36. @tombruijn Questions so far?

  37. @tombruijn Bonus

  38. @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?
  39. @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
  40. @tombruijn Demo and questions? https:/ /github.com/tombruijn/rebase-workshop-example-2

  41. @tombruijn How to rebase?

  42. @tombruijn Today we'll be refactoring on the command line This

    way we know how git work
  43. @tombruijn Interactive rebase Tell Git how to rebase git rebase

    --interactive <SHA/branch>
  44. @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
  45. @tombruijn Questions so far?

  46. @tombruijn Squashing Merge two commits together and keep their messages.

    Used for: • merging WIP work across commits
  47. @tombruijn Questions so far?

  48. @tombruijn Fixup Merge two commits together, only keep the first

    message. Used for: • typos • test fixes
  49. @tombruijn Let's practice rebasing https:/ /github.com/tombruijn/rebase-workshop-example-2

  50. @tombruijn Tips! Make notes!

  51. @tombruijn Gain confidence • Rebase more often • Rebase small

    • The smallest you can at a time
  52. @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) ❌
  53. @tombruijn Demo and questions?

  54. @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
  55. @tombruijn Demo and questions?

  56. @tombruijn git reflog • git reflog • Ref[erence] log •

    See all your actions in git • In a semi-human-readable format
  57. @tombruijn Demo and questions?

  58. @tombruijn git fixup • What are "fixup!" commits? • Mark

    commits as fixup commits for future rebasing • So you don't need to rebase now
  59. @tombruijn Demo and questions? https:/ /github.com/tombruijn/rebase-workshop-example-3

  60. @tombruijn Reviewing MRs/PRs How to leave a better review

  61. @tombruijn • We do this for our team • We

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

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

    any! • Worst case you learn something new
  64. @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? ❓
  65. @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!
  66. @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
  67. @tombruijn Boy scouting • When to fix style issues? •

    When to refactor?
  68. @tombruijn Questions? Ask me things git! tomdebruijn.com - for articles

    about git The last slide!