git is hard but time travel in git is easy. PRESENTATION BY MONICA POWELL @waterproofheart π www.aboutmonica.com/
A presentation at React Conf in October 2019 in Henderson, NV, USA by Monica Powell
git is hard but time travel in git is easy. PRESENTATION BY MONICA POWELL @waterproofheart π www.aboutmonica.com/
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
What is git? A distributed version-control system for tracking changes in source code during software development. @waterproofheart π www.aboutmonica.com/
What do GitLab, GitHub and Bitbucket have in common? @waterproofheart π www.aboutmonica.com/
TIME TRAVEL IN GIT Itβs not a bug! Itβs a feature. @waterproofheart π www.aboutmonica.com/
DEBUGGING @waterproofheart π www.aboutmonica.com/
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/
Thatβs not the only way to commit in the futureβ¦
How does language detection on GitHub.com work? @waterproofheart π www.aboutmonica.com/
Reclassify Auto-Detected Language With One Line of Code @waterproofheart π www.aboutmonica.com/
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/
.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/
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/
Git Hooks Workflow Automate your local git workflow @waterproofheart π www.aboutmonica.com/
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/
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/
CLI Output of Pre-Commit Hook @waterproofheart π www.aboutmonica.com/
Linting Hooks in Package.json with Husky πΆ @waterproofheart π www.aboutmonica.com/
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/
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/