auditorium google analytics has been moved ... - drupal govcon€¦ · drupal govcon 2016 google...

57
Untangling your code: a git workflow for Noobs Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium

Upload: others

Post on 25-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Untangling your code: a git workflow for Noobs

Drupal GovCon 2016

Google Analytics has been moved to the main Auditorium

Page 2: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Who are we?Dan ZinkevichDeveloper

ZivTech, Probo.ci

https://www.zivtech.com/about/team/daniel-zinkevich

Greg Lund-ChaixSenior Performance Engineer

Tag1 Consulting

https://tag1consulting.com/about/team#Greg-Lund-Chaix

Page 3: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

What we're going to coverThe Basics

The Four Rules

Write that code!

Store and Test

Deployment

Now What?

Page 4: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

In the beginning ...

Image credit: https://commons.wikimedia.org/wiki/File:Ohiopyle_rafting.jpg

Page 5: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Crunch time!

Image credit: https://commons.wikimedia.org/wiki/File:%27Shiiitttttt!!!%27-Rangitata_Valley_NZ-White_Water_Rafting.jpg

Page 6: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Basics

Page 7: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWho is using git now?

Page 8: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWho is using git now?

Who is using a git branching workflow?

Page 9: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWhat is git?

Page 10: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWhat is git?

git is a distributed version control system that "records changes to a file or set of files over time so that you can recall specific versions later."

https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

Page 11: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWhat is git?

git is a security blanket superhero cape!

Image credit: https://www.flickr.com/photos/personalcreations/15075538845

Page 12: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWhy git?

Page 13: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The BasicsWhy git?

Page 14: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Four Rules

Image credit: https://www.flickr.com/photos/chickspirit/3793649508

Page 15: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Four Rules

Rule #1:

All work is done in a branch.

Image credit: https://www.flickr.com/photos/chickspirit/3793649508

Page 16: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Four Rules

Rule #2:

Nobody merges their own code.

Image credit: https://www.flickr.com/photos/chickspirit/3793649508

Page 17: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Four Rules

Rule #3:

No editing on the server(s).

Image credit: https://www.flickr.com/photos/chickspirit/3793649508

Page 18: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

The Four Rules

Rule #4:

'master' branch is always deployable.

Image credit: https://www.flickr.com/photos/chickspirit/3793649508

Page 19: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer
Page 20: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Feature Branches!Feature branch (n): A set of changes to your site.

2 Defining Aspects:

Don’t work forever: Have a discrete goal so everyone knows when it’s done and whether the branch actually accomplishes its goal.

Have a base: A feature branch should branch off of another branch (master, development, integration, etc) that you know is safe; this branch should have no buggy code or hacks required to get it running.

Page 21: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Creating a feature branch[laptop]$ git checkout master

[laptop]$ git pull

[laptop]$ git checkout -b add-date-field-1

Page 22: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Write that code!

Page 23: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Site Building

Page 24: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Export those nodes & views![laptop]$ drush features-components node

[laptop]$ drush features-components views

[laptop]$ drush features-export sax_features node:saxamaphone views_view:saxamaphones -y

Page 25: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Write that code![laptop]$ git status

[laptop]$ git diff

[laptop]$ git add sax_features.views_default.inc

[laptop]$ git commit

Page 26: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Going Public With a BranchYou have been tasked with adding the date to the existing saxamaphones view. Let’s go!

Page 27: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Building the new view...

Page 28: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Update the feature[laptop]$ drush features-diff sax_features

[laptop]$ drush features-update sax_features -y

[laptop]$ git status

[laptop]$ git add sax_features.views_default.inc -p

[laptop]$ git commit

Page 29: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Pushing a feature branch to the repo

[laptop]$ git push -u

origin add-date-field-1

Page 30: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Pull RequestA pull request is a feature branch that can be merged back into the base branch.

Page 31: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Testing a PR: Setting up Probo.ci[laptop]$ mysqldump saxamaphone > sax.sql

[laptop]$ gzip sax.sql

[laptop]$ git add .probo.yaml

[laptop]$ git commit

Page 32: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Testing the pull request on Probo.ci

Page 33: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Someone else checks the code

Page 34: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Cool! The Lead Dev Merges

Page 35: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Meanwhile...While we were working on the date feature branch, our coworker was working on a similar branch that would edit the same view to add images.

Page 36: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Making the second feature branch[laptop]$ git checkout master

[laptop]$ git pull

[laptop]$ git checkout -b add-image-field-2

[laptop]$ drush features-diff sax_features

[laptop]$ drush features-update sax_features -y

[laptop]$ git status

[laptop]$ git add sax_features.views_default.inc -p

[laptop]$ git commit

Page 37: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

CONFLICT!Github won’t let us automatically merge the code because we both edited the same file in the same place.

Our coworker needs to rebase their branch off the latest in master.

Page 38: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

COULD THIS END WELL?WILL THINGS EVER BE OK AGAIN???

Page 39: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Yes! Rebase![laptop]$ git checkout master

[laptop]$ git pull

[laptop]$ git checkout add-image-field-2

[laptop]$ git rebase master

[laptop]$ git add sax_features.views_default.inc

[laptop]$ git rebase --continue

[laptop]$ git add sax_features.views_default.inc -p

[laptop]$ git commit

Page 40: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

HARMONY RESTORED

Page 41: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

HARMONY RESTORED

Page 42: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer
Page 43: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment

Uh oh!

Page 44: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment

AKA: Hack the Gibson!

Page 45: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment

AKA: YeeeeeHAW Cowboy!

Page 46: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment

Page 47: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment[laptop]$ git tag -a "3.0.3" -m "3.0.3 release"

[laptop]$ git push --tags

Page 48: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment[server]$ drush variable-set maintenance_mode 1

[server]$ drush sql-dump > /var/backup/my_db-`date +%Y%m%d`.sql

[server]$ git checkout master && git fetch --all

[server]$ git status

[server]$ git pull

[server]$ git checkout -b v3.0.3 3.0.3

[server]$ drush updatedb && drush features-revert-all -y

[server]$ drush variable-set maintenance_mode 0

Page 49: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Deployment

Page 50: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Wow! You all look convinced!!But what about your boss?

Your supervisor?

Your CTO?

Page 51: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Git saves time, money, and repMultiple people working on the same site, finish on time

Ease the pain of adding new people to a project

Confidence in your product

Client buy-in

No more buggy code on production

Rolling back code (EMERGENCY ONLY)

Page 52: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

https://s-media-cache-ak0.pinimg.com/236x/77/df/c4/77dfc40ffbf059532b3777d1914dc8d4.jpg

Page 53: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

HOW MANY MARBLES WERE THERE?

Page 54: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer
Page 55: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

https://s-media-cache-ak0.pinimg.com/236x/77/df/c4/77dfc40ffbf059532b3777d1914dc8d4.jpg

Page 56: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Resources● GitHub Flow - a lot of this presentation is a simplified version of GitHub Flow

https://guides.github.com/introduction/flow/http://scottchacon.com/2011/08/31/github-flow.html

● Tig - view git commit and log information, see what hasn't been pushed to upstream https://github.com/jonas/tig

● Git prompt & completion - see the branch and git status on your command linehttps://git-scm.com/book/en/v2/Git-in-Other-Environments-Git-in-Bash

● Git GUIs - visual thinker? Use a GUI!https://git-scm.com/downloads/guis

Page 57: Auditorium Google Analytics has been moved ... - Drupal GovCon€¦ · Drupal GovCon 2016 Google Analytics has been moved to the main Auditorium. Who are we? Dan Zinkevich Developer

Questions?Feel free to ping @gchaix (IRC/Twitter/Drupal.org/just about everywhere) or [email protected]