Git is Hard but Time Traveling in Git Isn’t

A presentation at Women Who Code NYC Lightning Talks in March 2019 in New York, NY, 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

Hi, I’m Monica Powell! I’m a Full Stack Engineer at Meetup and organizer of the React Ladies Meetup group. I’ve written about git and other tech adventures in publications such as FreeCodeCamp, Hacker Noon and Code Like A Girl. @waterproofheart 🔗 www.aboutmonica.com/

Slide 3

Slide 3

Talk Outline 1. Introduction 2. How to write git commits dated in the future 3. Changing the languages that GitHub auto-detects in a repository 4. Automating git workflow 5. Resources @waterproofheart 🔗 www.aboutmonica.com/

Slide 4

Slide 4

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

Slide 5

Slide 5

What is the relationship between GitHub/BitBucket/GitLab and git?? @waterproofheart 🔗 www.aboutmonica.com/

Slide 6

Slide 6

TIME TRAVEL IN GIT It’s not a bug! It’s a feature. @waterproofheart 🔗 www.aboutmonica.com/

Slide 7

Slide 7

DEBUGGING The marketing mix is a business tool used in marketing and by marketers, originally can be used @waterproofheart 🔗 www.aboutmonica.com/

Slide 8

Slide 8

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 9

Slide 9

Is that the only way to commit in the future? @waterproofheart 🔗 www.aboutmonica.com/

Slide 10

Slide 10

OTHER WAYS TO MODIFY COMMIT DATES

  • 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 11

Slide 11

What does this look like on GitHub? Write here a list of features, textboxes easy to edit Here you can write more More about your project. Statistics, analysis and content export GIT_AUTHOR_DATE=”Wed Mar 20 15:12:30 2019 -0700” export GIT_COMMITTER_DATE=”Wed Mar 20 15:12:30 2019 -0700” git commit -m “future commit” @waterproofheart 🔗 www.aboutmonica.com/

Slide 12

Slide 12

@waterproofheart 🔗 www.aboutmonica.com/

Slide 13

Slide 13

Reclassify Language With One Line of Code @waterproofheart 🔗 www.aboutmonica.com/

Slide 14

Slide 14

Linguist library Python Application + CSS = 98.9% CSS and 1.1% Other??? @waterproofheart 🔗 www.aboutmonica.com/

Slide 15

Slide 15

Linguist library “This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs.” https://github.com/github/linguist#my-repository-isnt-showing-my-la nguage @waterproofheart 🔗 www.aboutmonica.com/

Slide 16

Slide 16

Linguist library 1 2 3 @waterproofheart 🔗 www.aboutmonica.com/

Slide 17

Slide 17

GIT HOOKS Automate your git workflow @waterproofheart 🔗 www.aboutmonica.com/

Slide 18

Slide 18

1 TIME TRAVEL IN GIT Build better presentations in less time @waterproofheart 🔗 www.aboutmonica.com/

Slide 19

Slide 19

1 TIME TRAVEL IN GIT Build better presentations in less time @waterproofheart 🔗 www.aboutmonica.com/

Slide 20

Slide 20

What is a git hook? Bash scripts that are executed at specific points within the git workflow. precommit, postcommit, prepush, postpush, etc…. Git Hooks Documentation: https://git-scm.com/docs/githooks @waterproofheart 🔗 www.aboutmonica.com/

Slide 21

Slide 21

Where do they live? Every Git repository has a hidden .git/hooks directory with a script for each hook you can bind to. These can be modified. @waterproofheart 🔗 www.aboutmonica.com/

Slide 22

Slide 22

How can git hooks be used? ● 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 files. ● Send notifications after a commit is pushed ● Sending intl objects to be translated ● And 1270824+ other ways. @waterproofheart 🔗 www.aboutmonica.com/

Slide 23

Slide 23

Git Hook Package.json Example @waterproofheart 🔗 www.aboutmonica.com/

Slide 24

Slide 24

Git Hooks Bash Script 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 25

Slide 25

How can git hooks be used? @waterproofheart 🔗 www.aboutmonica.com/

Slide 26

Slide 26

Limitations of Git Hooks ● Limited enforcement - can easily be overridden —no-verify or forced pushes ● Local hooks != shared hooks as .git/hooks not in version control ● Doesn’t replace CI, server-side branch protection or code reviews @waterproofheart 🔗 www.aboutmonica.com/

Slide 27

Slide 27

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/gitatt ributes • Git Hook Templates https://github.com/pre-commit/pre-commit -hooks Git Hooks 101 Website https://githooks.com/ @waterproofheart 🔗 www.aboutmonica.com/

Slide 28

Slide 28

Thanks! Any questions? Feel free to reach out: monica@aboutmonica.com https://www.meetup.com/React-Ladies @waterproofheart 🔗 www.aboutmonica.com/