git is hard, but time travel in git is easy

A presentation at React Conf in October 2019 in Henderson, NV, USA by Monica Powell

Slide 1

Slide 1

git is hard but time travel in git is easy. PRESENTATION BY MONICA POWELL @waterproofheart πŸ”— www.aboutmonica.com/

Slide 2

Slide 2

Agenda Hi, I’m Monica Powell. I am a Full Stack Engineer at Meetup and organizer of the React Ladies community. Owner of too many domains including www.monica.dev. In a committed relationship with git. @waterproofheart

  1. Introduction: Git vs GitHub 2. How to write commits dated in the future 3. How to change the languages that GitHub autodetects 4. How to automate local git workflow πŸ”— www.aboutmonica.com/

Slide 3

Slide 3

What is git? A distributed version-control system for tracking changes in source code during software development. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 4

Slide 4

What do GitLab, GitHub and Bitbucket have in common? @waterproofheart πŸ”— www.aboutmonica.com/

Slide 5

Slide 5

TIME TRAVEL IN GIT It’s not a bug! It’s a feature. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 6

Slide 6

DEBUGGING @waterproofheart πŸ”— www.aboutmonica.com/

Slide 7

Slide 7

CREATE FUTURE COMMIT Checkout new branch Change computer time & replicate issue locally Squash bug and fix issue Commit and push fix Oops! 😬 @waterproofheart πŸ”— www.aboutmonica.com/

Slide 8

Slide 8

That’s not the only way to commit in the future…

  • The Date format must follow the Git standard RFC 2822 or ISO 8601. - Can rebase and apply changes commits to the past as well. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 9

Slide 9

How does language detection on GitHub.com work? @waterproofheart πŸ”— www.aboutmonica.com/

Slide 10

Slide 10

Reclassify Auto-Detected Language With One Line of Code @waterproofheart πŸ”— www.aboutmonica.com/

Slide 11

Slide 11

Linguist library β€’ An open-source GitHub project to generate language breakdown graphs. β€’ Supposed to ignore vendored (third-party ) files (i.e., Bootstrap, Node Modules) β€’ If a programming language isn’t listed in the Linguist’s YAML file, as far as Linguist in concerned it doesn’t exist. https://github.com/github/ linguist/blob/master/lib/linguist/languages.yml @waterproofheart πŸ”— www.aboutmonica.com/

Slide 12

Slide 12

.gitattributes and Linguist One-line change to reclassify my project from 98.9% CSS to 56.2% Python and 43.8% HTML 1) Create a .gitattributes file with the below one-liner: 2) reclassifies the repo according to the new rule in the .gitattributes ignoring the /static directory and treating it as third-party code. Note: Linguist ignores third-party, node_modules/ and bower_components/ by default. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 13

Slide 13

Git Hooks: You already have them! Under the hood of git repositories Every Git repository has a hidden .git/hooks directory with sample bash scripts for each hook you can bind to. These can be modified. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 14

Slide 14

Git Hooks Workflow Automate your local git workflow @waterproofheart πŸ”— www.aboutmonica.com/

Slide 15

Slide 15

Git Hooks Ideas ” Warn when committing to master ” Run Prettier, ESLint and Jest tests before committing ” Warn or abort when committing code with: console.logs(), sensitive credentials, merge conflict strings or large files. ” Send notifications after a commit is pushed ” Sending intl objects to be translated ” And 1270824+ other ways. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 16

Slide 16

Pre-Commit Hook Example Warn when committing to master Run linting and tests before committing Warn or abort when committing code with: console.logs(), sensitive credentials, merge conflict strings or large file Send notifications after a commit is pushed Sending intl objects to be translated And 1270824+ other ways. @waterproofheart πŸ”— www.aboutmonica.com/

Slide 17

Slide 17

CLI Output of Pre-Commit Hook @waterproofheart πŸ”— www.aboutmonica.com/

Slide 18

Slide 18

Linting Hooks in Package.json with Husky 🐢 @waterproofheart πŸ”— www.aboutmonica.com/

Slide 19

Slide 19

Limitations of Git Hooks ” Limited enforcement - can easily be overridden β€”no-verify, β€”no-merge, β€” no-checkout or forced pushes ” Local hooks != shared hooks as .git/hooks not in version control (although with Husky you can add hooks to package.json which is in version control) ” Doesn’t replace CI, server-side branch protection or code reviews @waterproofheart πŸ”— www.aboutmonica.com/

Slide 20

Slide 20

Helpful Git Resources β€’ Git Lens Plugin https://gitlens.amod.io/ β€’ Git Books https://git-scm.com/book/en/v2 β€’ git-together β€” better attribution β€’ https://github.com/kejadlen/git-together Husky 🐢 https://github.com/typicode/ husky β€’ Git Attributes templates https://github.com/alexkaratarakis/ gitattributes Git Hooks 101 Website https://githooks.com/ @waterproofheart β€’ Git Hook Templates https://github.com/pre-commit/pre-commithooks β€’ Linguist Library https://github.com/github/linguist/ πŸ”— www.aboutmonica.com/