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

Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You

Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You

Popular Git workflows (e.g., rebase-before-merge) have a side effect of destroying important aspects of the history of the branch being merged. Similarly, inexperienced or lazy developers that don't take the time to properly structure commits before pushing or merging can obscure important aspects of the history of the code being developed. Learn what these problems are, and how to avoid them.

As presented at LinuxFest Northwest, 07 May 2017

John SJ Anderson

May 07, 2017
Tweet

More Decks by John SJ Anderson

Other Decks in Programming

Transcript

  1. photo: https://cdn.pixabay.com/photo/2014/10/01/17/59/ my-little-pony-468916960720.jpg logs are magic! john sj anderson |

    @genehack | lfnw 2017 | 7 may 2017 1 — LFNW 2017 – 7 May 2017 – @genehack
  2. photo: https://cdn.pixabay.com/photo/2014/10/01/17/59/ my-little-pony-468916960720.jpg why git workflows & commit structure should

    matter to you john sj anderson | @genehack | lfnw 2017 | 7 may 2017 2 — LFNW 2017 – 7 May 2017 – @genehack
  3. In my day job, I'm the VP of Technology for

    Infinity, a small IT consultancy. vp, tech infinity interactive 4 — LFNW 2017 – 7 May 2017 – @genehack
  4. I wanted to give this talk because I love revision

    control. I've kept my home directory under revision control for over a decade, I maintain a Perl git wrapper module, and I wrote this thing called GitGot to automate batch ops across multiple Git repos (but that's a different talk) i ❤ revision control 5 — LFNW 2017 – 7 May 2017 – @genehack
  5. I liked SVN a bit more... svn 7 — LFNW

    2017 – 7 May 2017 – @genehack
  6. Hell, I even liked RCS rcs 8 — LFNW 2017

    – 7 May 2017 – @genehack
  7. Actually, that's a lie -- I don't think anybody liked

    RCS. Anybody here remember RCS? Anybody still using RCS? rcs 9 — LFNW 2017 – 7 May 2017 – @genehack
  8. And now we have git git 10 — LFNW 2017

    – 7 May 2017 – @genehack
  9. I love git. Git makes me happy i ❤ git

    11 — LFNW 2017 – 7 May 2017 – @genehack
  10. How many people have used git at least once? How

    many people feel comfortable in git? How many people would call themselves git "experts"? quick poll! 12 — LFNW 2017 – 7 May 2017 – @genehack
  11. So, if you're not at least a little familiar with

    git, this talk is probably not going to that interesting -- most of the stuff I'm going to talk about does apply to all revision control systems, but my examples and recommendations are all git-based what this talk isn't 13 — LFNW 2017 – 7 May 2017 – @genehack
  12. I'm also not going to be claiming to dispense any

    universal truths in this talk... no universal truths 14 — LFNW 2017 – 7 May 2017 – @genehack
  13. I'm not even going to try to convince you that

    anything I'm telling you is a "best practice". Pretty much anything I advocate in here, I'm sure people will be able to come up with an example where I'd say, "yeah, for that, don't do it" not even "best practices" 15 — LFNW 2017 – 7 May 2017 – @genehack
  14. So what is this talk about then? what this talk

    is 16 — LFNW 2017 – 7 May 2017 – @genehack
  15. Opinionated commentary on some aspects of using revision control systems...

    some opinions 17 — LFNW 2017 – 7 May 2017 – @genehack
  16. ...based on things I've seen over the past mumble years

    making extensive use of revision control on personal, open source, and commercial software projects photo modified from http://i2.kym-cdn.com/photos/images/original/ 001/044/247/297.png backed up with experience 18 — LFNW 2017 – 7 May 2017 – @genehack
  17. Some of this stuff may be more important for larger

    projects with multi-person teams ... maybe more important for larger projects 19 — LFNW 2017 – 7 May 2017 – @genehack
  18. ...but it's also important if you've just started a project

    that you're thinking might grow into something bigger. Having a solid project history from the get-go can make it a lot easier for contributors to come on board and start pitching in but also good for projects that aspire to be bigger 20 — LFNW 2017 – 7 May 2017 – @genehack
  19. but also applicable for doc or config repos 22 —

    LFNW 2017 – 7 May 2017 – @genehack
  20. Eventually we're going to talk about how to make better

    use of the history in your repos ... making better use of history 23 — LFNW 2017 – 7 May 2017 – @genehack
  21. ...but first, we're going to talk about ways to make

    better history making better history 24 — LFNW 2017 – 7 May 2017 – @genehack
  22. For all these things, there are a few common elements

    prerequisites 25 — LFNW 2017 – 7 May 2017 – @genehack
  23. For maximum value, you're going to want to apply them

    consistently consistency 26 — LFNW 2017 – 7 May 2017 – @genehack
  24. They're pretty much all the type of thing that if

    you do them all the time... do it all the time 28 — LFNW 2017 – 7 May 2017 – @genehack
  25. ...you eventually will just do them without thinking too much

    about it then you don't have to think about it 29 — LFNW 2017 – 7 May 2017 – @genehack
  26. or even better, if you're the right kind of twisted...

    even better 30 — LFNW 2017 – 7 May 2017 – @genehack
  27. ...you'll automate things. for example, i periodically run some scripts

    to find repos in a "dirty" state, or that have local commits that haven't been pushed to a remote, and then clean them up automate it 31 — LFNW 2017 – 7 May 2017 – @genehack
  28. so, moving on to how to make better history how

    to make better history 32 — LFNW 2017 – 7 May 2017 – @genehack
  29. if you're going to talk about git, you almost have

    to talk about workflows. potentially one of the more contentious aspects of starting a new project is deciding what your workflow is going to be workflows 33 — LFNW 2017 – 7 May 2017 – @genehack
  30. workflows can range from the very simple -- just a

    single branch in a local-only repo, just adding commits onto the HEAD of that branch photo credit: modified by https://www.flickr.com/photos/appleboy/ 5488984566/in/photostream/ no remote no branches master only 34 — LFNW 2017 – 7 May 2017 – @genehack
  31. or you can have that basic setup, but with a

    remote that you push things to every so often. this is basically the simplest possible branching workflow -- when you have local commits you haven't pushed to the remote yet, that's (if you squint, a bit) a branch photo credit: modified from https://www.flickr.com/photos/appleboy/5488387469/in/ photostream/ local master no branches & periodic pushes 35 — LFNW 2017 – 7 May 2017 – @genehack
  32. all the way up to fairly complicated workflows like git

    flow, where you have multiple branches in flight at any given point. anybody using git flow, or anything equivalent? photo credit: https://www.flickr.com/photos/appleboy/ 5488984404/in/photostream/ git flow 36 — LFNW 2017 – 7 May 2017 – @genehack
  33. this is basically doing extra work to mimic what a

    fast forward merge probably would have done rebase before merge 40 — LFNW 2017 – 7 May 2017 – @genehack
  34. a linear commit history is a lie 43 — LFNW

    2017 – 7 May 2017 – @genehack
  35. a linear commit history is a lie (probably) 44 —

    LFNW 2017 – 7 May 2017 – @genehack
  36. release may be master release may be another branch 51

    — LFNW 2017 – 7 May 2017 – @genehack
  37. merging to the release branch is a release 53 —

    LFNW 2017 – 7 May 2017 – @genehack
  38. git config --global merge.ff false git config --global pull.ff only

    58 — LFNW 2017 – 7 May 2017 – @genehack
  39. [merge] ff = false [pull] ff = only 59 —

    LFNW 2017 – 7 May 2017 – @genehack
  40. [alias] br = branch ci = commit -v co =

    checkout st = status 63 — LFNW 2017 – 7 May 2017 – @genehack
  41. the ticket id should be in the branch name 78

    — LFNW 2017 – 7 May 2017 – @genehack
  42. put the number at the end of the branch name

    80 — LFNW 2017 – 7 May 2017 – @genehack
  43. important: at each commit the software must work 102 —

    LFNW 2017 – 7 May 2017 – @genehack
  44. develop a habit of using checkpoint commits instead of the

    stash savepoints 112 — LFNW 2017 – 7 May 2017 – @genehack
  45. may be useful to preserve dead ends 123 — LFNW

    2017 – 7 May 2017 – @genehack
  46. you can customize the template for the commit message 128

    — LFNW 2017 – 7 May 2017 – @genehack
  47. if you get to this point, you're also going to

    want to script the repo setup process git config --local commit.template ./.template # edit .template to add whatever you want... 129 — LFNW 2017 – 7 May 2017 – @genehack
  48. good: make login form use POST instead of GET [#864]

    131 — LFNW 2017 – 7 May 2017 – @genehack
  49. or at least make yourself look smart 145 — LFNW

    2017 – 7 May 2017 – @genehack
  50. [color] branch = auto diff = auto grep = auto

    interactive = auto showbranch = auto status = auto ui = auto 151 — LFNW 2017 – 7 May 2017 – @genehack
  51. [color "status"] added = green bold changed = red bold

    untracked = cyan bold 152 — LFNW 2017 – 7 May 2017 – @genehack
  52. SHA in red, branch name (if any) in yellow, commit

    subject, date, author `--pretty=format: '%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'` 172 — LFNW 2017 – 7 May 2017 – @genehack
  53. it's probably worth more of your time 176 — LFNW

    2017 – 7 May 2017 – @genehack
  54. don't just stop when the software works 178 — LFNW

    2017 – 7 May 2017 – @genehack
  55. be kind to your future self 181 — LFNW 2017

    – 7 May 2017 – @genehack
  56. thanks! lfnw organizers & volunteers linus & others for git

    YOU! 182 — LFNW 2017 – 7 May 2017 – @genehack
  57. questions? (ps: please fill out the talk eval form!) 184

    — LFNW 2017 – 7 May 2017 – @genehack