Slide 1

Slide 1 text

STORY-TELLING WITH GIT REBASE Elle Meredith @aemeredith Blackmill @blackmillco

Slide 2

Slide 2 text

Complexity

Slide 3

Slide 3 text

Communicate

Slide 4

Slide 4 text

Version Control System

Slide 5

Slide 5 text

A project’s history is its most valuable documentation Ref: https://mislav.net/2014/02/hidden-documentation/

Slide 6

Slide 6 text

Kept forever

Slide 7

Slide 7 text

Always in sync with the code

Slide 8

Slide 8 text

Are available to everyone

Slide 9

Slide 9 text

Searchable

Slide 10

Slide 10 text

$ git log --grep regexp

Slide 11

Slide 11 text

SMALL COMMITS 1

Slide 12

Slide 12 text

commit [REDACTED] Date: [REDACTED] - add promotions to custom brand bundles - add bundle promotions to custom brands - generate unique custom promo code key - remove validation for nested create - remove binding.pry - update to allow default bundle (no promo) - refactor for empty promotion - tmp precompile assets - refactor dynamic promo code - adding tracking, top/bottom code - removing unused method calls, redundant migration - use scope - style with Rubocop validation - update asset path, fix broken specs - tmp disable integration spec 20 files changed, 349 insertions(+), 129 deletions(-)

Slide 13

Slide 13 text

How big or small should a commit be?

Slide 14

Slide 14 text

$ git add -p

Slide 15

Slide 15 text

Image credit: http://www.artslife.com/2014/09/22/people-places-steve-mccurry-alla-south- bank-tower- no-al-279/ GOOD COMMIT MESSAGES 2

Slide 16

Slide 16 text

Ref: http://stevetarver.github.io/2016/02/19/intentional-git-comments.html Image credit: https://burst.shopify.com/photos/train-turning-through-fog 1. Clarity of intent 2. Clarity of thought 3. Ability to reason about the code

Slide 17

Slide 17 text

Ref: https://github.com/kristinabrown/dinner-dash/commits/master?page=5

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

$ Fix failed specs

Slide 20

Slide 20 text

$ Fix this

Slide 21

Slide 21 text

$ Fix stuff

Slide 22

Slide 22 text

$ Changed stuff

Slide 23

Slide 23 text

$ Testing git push

Slide 24

Slide 24 text

$ Adjust css

Slide 25

Slide 25 text

$ Bug fix

Slide 26

Slide 26 text

$ More work

Slide 27

Slide 27 text

$ Minor changes

Slide 28

Slide 28 text

$ Work on feature XYZ

Slide 29

Slide 29 text

$ Change X constant to be 10

Slide 30

Slide 30 text

$ Whoops

Slide 31

Slide 31 text

$ Should work now

Slide 32

Slide 32 text

$ WTF? Ref: https://www.codelord.net/2015/03/16/bad-commit-messages-hall-of-shame/

Slide 33

Slide 33 text

Image credit: https://weheartit.com/entry/104254659

Slide 34

Slide 34 text

ANSWER 5 QUESTIONS Why is this change necessary? How does it address the issue? What side e ects does this change have? Were other solutions considered? Include a reference [to a discussion, resource, ticket ] Ref: https://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message

Slide 35

Slide 35 text

Present-tense summary under 50 characters * More information about commit (under 72 chars). * More information about commit (under 72 chars). http://project.management-system.com/ticket/123

Slide 36

Slide 36 text

Present-tense summary under 50 characters * More information about commit (under 72 chars). * More information about commit (under 72 chars). http://project.management-system.com/ticket/123

Slide 37

Slide 37 text

Present-tense summary under 50 characters * More information about commit (under 72 chars). * More information about commit (under 72 chars). http://project.management-system.com/ticket/123

Slide 38

Slide 38 text

commit [REDACTED] Author: Elle Meredith Date: [REDACTED] Add author's name to opportunity form - This input field is disabled - so that the user cannot edit the field - It displays the author's name on: - create a new opportunity - edit an existing opportunity - reposting an opportunity - If the author doesn't have a first or last name, display the author's email instead Trello: https://trello.com/c/12345

Slide 39

Slide 39 text

1. Add (340 times) 2. Update (339 times) 3. Remove / Delete (135 times) 4. Fix (132 times) 5. Use (76 times) 6. Style (56 times) 7. Allow (53 times) 8. Bump (50 times) 9. Show (44 times) 10. Refactor / Clean (35 times) Apply / Change / Con gure / Create / Deprecate / Disable / Display / Drop / Enable / Ensure / Extract / Handle / Improve / Increase / Limit / Link / Make / Migrate / Rename / Set / Skip / Sort / Support / Validate / Wire

Slide 40

Slide 40 text

SMALL FEATURE BRANCHES 3

Slide 41

Slide 41 text

Encapsulation

Slide 42

Slide 42 text

Pull requests and code reviews

Slide 43

Slide 43 text

1. Create a new branch $ git checkout -b em-feature-branch

Slide 44

Slide 44 text

2. Update the branch, commit new changes $ git status $ git add $ git commit

Slide 45

Slide 45 text

3. Push changes in the branch to `origin` $ git push -u origin em-feature-branch or $ git push origin head

Slide 46

Slide 46 text

4. Open a PR for feedback

Slide 47

Slide 47 text

5. Implement changes based on feedback

Slide 48

Slide 48 text

6. Rebase master on the branch interactively and push updated branch back up $ git rebase -i master $ git push origin head -f

Slide 49

Slide 49 text

6. Rebase master on the branch interactively and push updated branch back up $ git rebase -i master $ git push origin head -f

Slide 50

Slide 50 text

7. Then fast forward merge to master $ git checkout master $ git merge --ff-only em-feature-branch

Slide 51

Slide 51 text

8. Lastly clean up the branches $ git push origin :em-feature-branch $ git branch -d em-feature-branch Ref: https://github.com/thoughtbot/guides/tree/master/protocol/git

Slide 52

Slide 52 text

MERGING VS REBASING

Slide 53

Slide 53 text

$ git merge --no-ff em-feature-branch

Slide 54

Slide 54 text

Image credit: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Rebasing

Slide 57

Slide 57 text

$ git rebase -i origin/master

Slide 58

Slide 58 text

$ git rebase --continue $ git rebase --abort

Slide 59

Slide 59 text

Slide 60

Slide 60 text

Rebase 34020519..5eac86e0 onto 34020519 (2 commands) Commands: p, pick = use commit r, reword = use commit, but edit the commit message e, edit = use commit, but stop for amending s, squash = use commit, but meld into previous commit f, fixup = like "squash", but discard this commit's log message x, exec = run command (the rest of the line) using shell d, drop = remove commit l, label = label current HEAD with a name t, reset = reset HEAD to a label m, merge [-C | -c ] [# ] create a merge commit using the original merge commit's message (or the oneline, if no original merge commit was specified). Use -c to reword the commit message. These lines can be re-ordered;\they are executed from top to bottom. If you remove a line here THAT COMMIT WILL BE LOST. However, if you remove everything, the rebase will be aborted. Note that empty commits are commented out

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Auto-squash and xup Ref: https://robots.thoughtbot.com/autosquashing-git-commits

Slide 63

Slide 63 text

Slide 64

Slide 64 text

$ git commit --fixup $ git rebase --interactive --autosquash master

Slide 65

Slide 65 text

$ git config --global rebase.autosquash true

Slide 66

Slide 66 text

Rebase often to grab recent updates from `master` Use rebase when you want to keep a linear commit history Never use rebase on a public/shared branch- i.e. never rebase `master`

Slide 67

Slide 67 text

WASH, RINSE, AND REPEAT

Slide 68

Slide 68 text

Make small feature- speci c commits

Slide 69

Slide 69 text

Write good commit messages

Slide 70

Slide 70 text

Work in small thematic feature branches

Slide 71

Slide 71 text

Rebase frequently to incorporate upstream changes

Slide 72

Slide 72 text

Review and revise history before sharing

Slide 73

Slide 73 text

Keep history linear

Slide 74

Slide 74 text

Auto-squash commits

Slide 75

Slide 75 text

THANK YOU! Elle Meredith @aemeredith Blackmill @blackmillco Edward watching over my sourdough