Slide 1

Slide 1 text

@tombruijn Git workshop Tom de Bruijn tomdebruijn.com

Slide 2

Slide 2 text

@tombruijn Agenda • Why this workshop? • Git rebasing • Reviewing Pull/Merge Requests

Slide 3

Slide 3 text

@tombruijn Interactive workshop That means you get to ask questions and do things

Slide 4

Slide 4 text

@tombruijn This is a practical workshop Let's first discuss some theory And then apply it in practice

Slide 5

Slide 5 text

@tombruijn Goal of workshop • Introduction to rebasing • Why rebase? • Explain how to rebase • Encourage you to rebase more

Slide 6

Slide 6 text

@tombruijn Make notes! You know the best way to remember things In your own words

Slide 7

Slide 7 text

@tombruijn Ask questions! Any time is good

Slide 8

Slide 8 text

@tombruijn Questions so far? (This type of slide is also a hint for myself)

Slide 9

Slide 9 text

@tombruijn Don't be afraid of Git! We can restore things Things don't disappear never to be seen again

Slide 10

Slide 10 text

@tombruijn Rebasing Why? What? How? When?

Slide 11

Slide 11 text

@tombruijn Why rebase? • Updating branches on other branches • Include other people's bug fixes in your branch • Alternative to a merge commit

Slide 12

Slide 12 text

@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

Slide 13

Slide 13 text

@tombruijn Commits to avoid • WIP • Fix test/bug • Merge commits • Instead, rebase

Slide 14

Slide 14 text

@tombruijn In short: To create a more readable git history

Slide 15

Slide 15 text

@tombruijn Questions so far?

Slide 16

Slide 16 text

@tombruijn Why a readable history? • We do this for our team • We do this for our future selves From: Git is about communication presentation

Slide 17

Slide 17 text

@tombruijn ✅ Better communication • git blame, git log ✅ Better reviews ✅ Faster reviews ✅ Faster debugging From: Git is about communication presentation

Slide 18

Slide 18 text

@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

Slide 19

Slide 19 text

@tombruijn Rebasing on another branch Rebasing on the branch we branched off from Get the latest bug fixes and features

Slide 20

Slide 20 text

@tombruijn Rebasing goal • Rebase feature branch on main branch • To include bug fixes in our branch • Prevent merge conflicts when merging our feature branch ✅

Slide 21

Slide 21 text

@tombruijn A visual example Today we'll be using learngitbranching.js.org/?NODEMO

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

@tombruijn Feature branch rebasing How to tidy up a branch for review

Slide 24

Slide 24 text

@tombruijn Imagine...

Slide 25

Slide 25 text

@tombruijn You get assigned an issue to add a button to the user profile page

Slide 26

Slide 26 text

@tombruijn At the end of the day you commit everything you have so far and sign off

Slide 27

Slide 27 text

@tombruijn The next day you realize you better refactor the button component making it easier to use

Slide 28

Slide 28 text

@tombruijn There was also a change on the main branch you needed to continue ⚠

Slide 29

Slide 29 text

@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 ✅

Slide 30

Slide 30 text

@tombruijn Questions so far? About our rebasing goals

Slide 31

Slide 31 text

@tombruijn Git history • WIP • Add button • Merge branch "main" • Refactor button component • Fix tests Older Newer

Slide 32

Slide 32 text

@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?

Slide 33

Slide 33 text

@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

Slide 34

Slide 34 text

@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

Slide 35

Slide 35 text

@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

Slide 36

Slide 36 text

@tombruijn Questions so far?

Slide 37

Slide 37 text

@tombruijn Bonus

Slide 38

Slide 38 text

@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?

Slide 39

Slide 39 text

@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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

@tombruijn How to rebase?

Slide 42

Slide 42 text

@tombruijn Today we'll be refactoring on the command line This way we know how git work

Slide 43

Slide 43 text

@tombruijn Interactive rebase Tell Git how to rebase git rebase --interactive

Slide 44

Slide 44 text

@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

Slide 45

Slide 45 text

@tombruijn Questions so far?

Slide 46

Slide 46 text

@tombruijn Squashing Merge two commits together and keep their messages. Used for: • merging WIP work across commits

Slide 47

Slide 47 text

@tombruijn Questions so far?

Slide 48

Slide 48 text

@tombruijn Fixup Merge two commits together, only keep the first message. Used for: • typos • test fixes

Slide 49

Slide 49 text

@tombruijn Let's practice rebasing https:/ /github.com/tombruijn/rebase-workshop-example-2

Slide 50

Slide 50 text

@tombruijn Tips! Make notes!

Slide 51

Slide 51 text

@tombruijn Gain confidence • Rebase more often • Rebase small • The smallest you can at a time

Slide 52

Slide 52 text

@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) ❌

Slide 53

Slide 53 text

@tombruijn Demo and questions?

Slide 54

Slide 54 text

@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

Slide 55

Slide 55 text

@tombruijn Demo and questions?

Slide 56

Slide 56 text

@tombruijn git reflog • git reflog • Ref[erence] log • See all your actions in git • In a semi-human-readable format

Slide 57

Slide 57 text

@tombruijn Demo and questions?

Slide 58

Slide 58 text

@tombruijn git fixup • What are "fixup!" commits? • Mark commits as fixup commits for future rebasing • So you don't need to rebase now

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

@tombruijn • We do this for our team • We do this for our future selves From: Git is about communication presentation

Slide 62

Slide 62 text

@tombruijn ✅ Better communication ✅ Better reviews ✅ Faster reviews ✅ Faster debugging From: Git is about communication presentation

Slide 63

Slide 63 text

@tombruijn Leave better reviews • Ask questions if you have any! • Worst case you learn something new

Slide 64

Slide 64 text

@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? ❓

Slide 65

Slide 65 text

@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!

Slide 66

Slide 66 text

@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

Slide 67

Slide 67 text

@tombruijn Boy scouting • When to fix style issues? • When to refactor?

Slide 68

Slide 68 text

@tombruijn Questions? Ask me things git! tomdebruijn.com - for articles about git The last slide!