Personal git workflow... for everyone!

for better, collaborative development

Presentation by Chris Russo of Savas Labs

What we'll cover

  • Brief discussion of what git is
  • Discuss the why of the proposed workflow
  • Look at the theory
  • Eff it, we'll do it live, step by step
  • Q&A

Prerequesites

It's best if you already...
  • use git for your development
  • know the git add, commit, push, and pull commands
  • take me, at most, 82.5% seriously

What is git?

  • git is a distributed "SCMS" or "version control" software tool optimized for
    • team collaboration
    • documentation
    • deployment

git strengths vs. other SCMS tools

  • Staging area
  • Data integrity
  • Distributed

What are we trying to accomplish?

The idea of the proposed workflow ensures that you are...

  • backing up code frequently
  • sharing the best of your code with your peers regardless of what your journey looked like
epic fail
Worse yet

What does the workflow address?

  • Fear of Commitment. Developers/perfectionists/humans have it.
    • You feel vulnerable
    • The pursuit of “something better”
    • Unrealistic expectations
    • Feeling “trapped”
  • Inconsistent backups due to #FoC.
  • Inefficient development due to #FoC. Preserve your possibly sloppy yet efficient development workflow and share only the best!

What does the workflow address?

Lack of self-reflection.
Socrate
You give yourself a code review!

Stop talking already!!! What is the workflow?

  1. Commit, commit, commit. Did you commit yet?
  2. Push up to a personal, private repository
  3. Polish, rewind history, and rewrite
  4. Share away!
  5. Rinse, repeat as needed

Specifics, though!

  1. git commit, git add, git commit, git add, git commit
  2. git push [backup-private-repository] [WIP-feature-branch]
  3. git reset [commit-before-wip-commits] --hard
  4. git checkout [WIP-feature-branch] .
  5. git reset HEAD
  6. git add -p
  7. git commit -v
  8. git cat-file -p
  9. git push [shared-repository] [SHARED-BRANCH]
  10. ...
  11. profit

I am angry! Is it really that simple?

Yes.

Step 1

Commit the good, the bad, the ugly

						
git show forgotten-buckets-feature^^^^^^
+}
+
+/**
+ * Function to queue up text and email reminders from cron runs.
+ */
+function compost_customizations_queue_forgotten_bucket_emails() {
+
+  // Retrieve all members who have been marked as a forgotten
+  // bucket but have not yet been notified
+  $query = new EntityFieldQuery();
+
+  $query->entityCondition('entity_type', 'user')
+    ->fieldCondition('field_active', 'value', 1);
+    //->fieldCondition('field_reminded_about_forgotten_b', 'value', 0);
+
+  $result = $query->execute();
+  $user_uids = array_keys($result['user']);
+  $users = entity_load('user', $user_uids);
+
+  foreach ($users as $user) {
+    if (empty($user->field_forgotten_bucket)) {
+      continue;
+    }
+
+    foreach ($user->field_forgotten_bucket[LANGUAGE_NONE] as $forgotten_bucket) {
+      $collection_id = $forgotten_bucket['value'];
+      $forgotten_bucket_entity = entity_load('field_collection_item', array($collection_id));
+      $reminded = $forgotten_bucket_entity[$collection_id]->field_reminded_about_forgotten_b...;
+      // If they weren't reminded, let's queue them up, and set them to reminded
+      if (!$reminded) {
+        // @todo: Queue email
+        $user_wrapper = entity_metadata_wrapper('user', $user);
+        $raw_collection = $user_wrapper->field_forgotten_bucket->value();
+        //$raw_collection[0]->field_reminded_about_forgotten_b->set(1);
+        $collection = entity_metadata_wrapper('field_collection_item', $raw_collection[0]);
+        $collection->field_reminded_about_forgotten_b->set(1);
+        // @todo: remove after finishing
+        if ($collection_id == 6) {
+          // Set to reminded
+          $collection->save();
+        }
+
+
+        $been = 'reminded?';
+      }
+    }
+  }
}
						
					
TRC source commit on github.com
Go back | Go forward

Step 2

Find you a nice, private repository

...that nobody knows about

git remote -v
backup	git@bitbucket.org:savaslabs/tilthy-rich-compost.git (fetch)
backup	git@bitbucket.org:savaslabs/tilthy-rich-compost.git (push)
upstream	git@github.com:chrisarusso/Tilthy-Rich-Compost-Website.git (fetch)
upstream	git@github.com:chrisarusso/Tilthy-Rich-Compost-Website.git (push)
					
And push, push, push!

Step 2.pepa

Pa, push it real good!

salt & peppa

Step 2.5

Finish up and polish code in last commit

Polished code


+}
+
+/**
+ * Loop through and queue up reminder notifications to subscribers
+ * who have not notified us of a collection that can be skipped
+ */
+function compost_customizations_queue_forgotten_bucket_emails() {
+
+  // Retrieve all members who have been marked as a forgotten
+  // bucket but have not yet been notified
+  $query = new EntityFieldQuery();
+
+  $query->entityCondition('entity_type', 'user')
+    ->fieldCondition('field_active', 'value', 1)
+    // We started this new system in 2015-July, so let's ignore any records
+    // before we changed to field collections
+    ->fieldCondition('field_forgotten_bucket', 'value', '0', '>=');
+
+  $result = $query->execute();
+  $user_uids = array_keys($result['user']);
+  $users = entity_load('user', $user_uids);
+
+  foreach ($users as $user) {
+    if (empty($user->field_forgotten_bucket)) {
+      continue;
+    }
+
+    $user_wrapper = entity_metadata_wrapper('user', $user);
+    $raw_collections = $user_wrapper->field_forgotten_bucket->value();
+
+    foreach ($raw_collections as $collection) {
+      $forgotten_bucket = entity_metadata_wrapper('field_collection_item', $collection);
+      $date = $forgotten_bucket->field_forgotten_bucket_date->value();
+      $reminded = $forgotten_bucket->field_reminded_about_forgotten_b->value();
+      $start_of_auto_reminders = strtotime('2015-Jul-01');
+      if (!$reminded && $date >= $start_of_auto_reminders) {
+        // Queue email
+        $email_queue = DrupalQueue::get('forgotten_bucket_notifications');
+        $data = array('user' => $user, 'date' => $date);
+        $email_queue->createItem($data);
+        // Set to reminded
+        $forgotten_bucket->field_reminded_about_forgotten_b->set(1);
+        $forgotten_bucket->save();
+      }
+    }
+  }
+}
							+
Was this

Step 2.668686

Mark the tree

dog marking tree

dog marking tree
Disclaimer: upcoming deeper dive

Understanding the commit object

							
CAR-computer:trc chris$ git cat-file -p b464b45
tree f2f767cefda3d283f0fb3b68fd4f377e554b7f57
parent a313c886ac6f2f85d97679faae12dc78900d34c9
author Chris Russo <chris.andrews.russo@gmail.com> 1436206446 -0400
committer Chris Russo <chris.andrews.russo@gmail.com> 1436206446 -0400

Final commit after testing, clean up time!
						
Note: Tree = f2f767c...
Forward

Understanding the tree object

							
CAR-computer:trc chris$ git cat-file -p f2f767
040000 tree 58c541257a7944223814aa69b13d0a73204995e9	assets
040000 tree 6bbcedb9daddca2da40e994137a9922630a88fa7	civicrm
040000 tree 49a4db16751992f17eb998cd8464bf7b31534165	drupalroot
040000 tree 421e8ebc4a7eed08583b24cc20298cf8cc8426fd	scripts
						
Note: This is the git project root

Understanding a tree object with blobs (files)

							
CAR-computer:trc chris$ git cat-file -p 49a4db1
100644 blob a1211d6396d2c011ea756410658b1c6b60b2078c	.gitignore
100644 blob b7c9dc638c1072ab6fb97a00940016074df275d5	.htaccess
100644 blob 5ba3523ade1dc77ae3ffe1de50795cb4b9193db6	CHANGELOG.txt
100644 blob dc8a855fbbecf09f939dba807fa5ebc1d8a26a05	COPYRIGHT.txt
100644 blob 95a873433350f02a4621124d054e531c83df984b	INSTALL.mysql.txt
100644 blob 8fe80433bd67d4659831ceaa729c534c70544c16	INSTALL.pgsql.txt
100644 blob 8e57d60cc0d793862706f41dcfdcef5252fdb1e8	INSTALL.sqlite.txt
100644 blob 6f02c05ae6dfd799a8a0566fccb54963ca9a595a	INSTALL.txt
100644 blob d159169d1050894d3ea3b98e1c965c4058208fe1	LICENSE.txt
100644 blob f5cf6f893abdb884ae8b95536c86224bc196400e	MAINTAINERS.txt
100644 blob 60d3da592e9ca5e77a4d40f1cc87e9f326bcf1b8	README.txt
100644 blob e870ff0f0ec39cb94b775e7689cbfec7a0a43afa	UPGRADE.txt
100644 blob 3ea2b20ace5146a5983dcebe6178fd5a53f00bd3	authorize.php
100644 blob c6ce5317e88fda48a6543ebcbcc09ec93e9d99ac	cron.php
040000 tree 64ae554e8a2d34a1065f19781155defae2321eed	includes
100644 blob 8b831997815f521b150c5b0c27038f6b04e3cf40	index.php
100644 blob 685d3b4ee3030809ff568b72a499b4170151f601	install.php
040000 tree 6136fb8262f157e233dff279f8038b4d3c63299e	misc
040000 tree fdff3556aa49c077b69552ab3dc70ce9c6addbbb	modules
040000 tree 834a5a0e372a2835965dfbba2602118575b2780c	profiles
100644 blob ff9e28687d65f7d3206ac7aef1e1a72d620d972e	robots.txt
040000 tree 2f73b7f8d323b2502d80b92940a1210c8a8568f1	scripts
040000 tree 0bf42bdca922725c1b8aca3824f121e2fb68c970	sites
040000 tree 4d21cf083db371f9078bdc1bd72876ab16428f50	themes
100644 blob d79270305a717064b9c2b8a324d4ecd0526a89ae	update.php
100644 blob 09983d92542ed094f9bd061af6c07adfdd745b91	web.config
						
Note: These are typical Drupal files in the drupal docroot

Step 3

Rollback

  • Rollback code to before you made any of your updates. This is likely where master is, or at least was when you made your feature branch.
  • 								
    CAR-computer:drupalroot chris$ git branch -v --contains 96edd7c2a5b0baccc9fe3233c4482d0254a41386
    * forgotten-buckets-feature                b464b45 Final commit after testing, clean up time!
    
    CAR-computer:drupalroot chris$ git branch -v --contains 96edd7c2a5b0baccc9fe3233c4482d0254a41386^
    * forgotten-buckets-feature                b464b45 Final commit after testing, clean up time!
    
    CAR-computer:drupalroot chris$ git branch -v --contains 96edd7c2a5b0baccc9fe3233c4482d0254a41386^^
    * forgotten-buckets-feature                b464b45 Final commit after testing, clean up time!
    
    CAR-computer:drupalroot chris$ git branch -v --contains 96edd7c2a5b0baccc9fe3233c4482d0254a41386^^^
    forgotten-buckets-feature b464b45 Final commit after testing, clean up time!
    * master                    808f61e Hide extra links for blog content type
    							
    						

The rollback

							
CAR-computer:drupalroot chris$ git reset 96edd7c2a5b0baccc9fe3233c4482d0254a41386^^^ --hard
HEAD is now at 3e4a0cc Remove bucket size from subscriber option
CAR-computer:drupalroot chris$ git status
On branch master
Your branch is behind 'upstream/master' by 13 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working directory clean
							
						

Step 3.5

Checkout polished code to working tree

  • Now we'll bring back all the code we just worked on, but not the commits with them.

CAR-computer:tilthy-rich-compost chris$ git checkout forgotten-buckets-feature .
CAR-computer:tilthy-rich-compost chris$ git status
On branch master
Your branch is behind 'upstream/master' by 13 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes to be committed:
(use "git reset HEAD ..." to unstage)

new file:   drupalroot/sites/all/modules/contrib/bcc/LICENSE.txt
new file:   drupalroot/sites/all/modules/contrib/bcc/README.TXT
new file:   drupalroot/sites/all/modules/contrib/bcc/bcc.info
new file:   drupalroot/sites/all/modules/contrib/bcc/bcc.install
new file:   drupalroot/sites/all/modules/contrib/bcc/bcc.module
new file:   drupalroot/sites/all/modules/contrib/field_collection/LICENSE.txt
new file:   drupalroot/sites/all/modules/contrib/field_collection/README.txt
new file:   drupalroot/sites/all/modules/contrib/field_collection/ctools/relationships/field_collection_from_field.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/field-collection-item.tpl.php
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.admin.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.api.php
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.info
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.info.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.install
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.migrate.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.module
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.pages.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.test
new file:   drupalroot/sites/all/modules/contrib/field_collection/field_collection.theme.css
new file:   drupalroot/sites/all/modules/contrib/field_collection/views/field_collection.views.inc
new file:   drupalroot/sites/all/modules/contrib/field_collection/views/field_collection_handler_relationship.inc
modified:   drupalroot/sites/all/modules/custom/compost_customizations/compost_customizations.module
new file:   drupalroot/sites/all/modules/custom/compost_customizations/templates/forgotten-bucket-email.tpl.php
					

Step 3.848

Reset staged files

  • We'll reset everything not with --hard so that nothing is staged

CAR-computer:tilthy-rich-compost chris$ git reset HEAD
Unstaged changes after reset:
M	drupalroot/sites/all/modules/custom/compost_customizations/compost_customizations.module
CAR-computer:tilthy-rich-compost chris$ git status
On branch master
Your branch is behind 'upstream/master' by 13 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

	modified:   drupalroot/sites/all/modules/custom/compost_customizations/compost_customizations.module

	Untracked files:
	(use "git add <file>..." to include in what will be committed)

		drupalroot/sites/all/modules/contrib/bcc/
		drupalroot/sites/all/modules/contrib/field_collection/
		drupalroot/sites/all/modules/custom/compost_customizations/templates/forgotten-bucket-email.tpl.php

no changes added to commit (use "git add" and/or "git commit -a")
				

Step 4

Make all new commits

New git history


CAR-computer:tilthy-rich-compost chris$ git log 3706ca31771312646f0caf0356cbc9ee3b2f4533
commit 3706ca31771312646f0caf0356cbc9ee3b2f4533
Author: Chris Russo 
Date:   Mon Jul 6 14:21:20 2015 -0400

Notify subscribers for missed collections

Add a template file for email copy
Add logic to cron to loop through and mail
users after they've not notified us
but have not left their bucket out

Remove old paypal templates and libraries
that aren't being used

commit f79d6b54a3a7ee25cb391f0978abf85314113461
Author: Chris Russo 
Date:   Fri Jul 3 16:11:51 2015 -0400

Add field collection module

This was done to link a specific forgotten bucket date
with a flag as to whether or not the user was notified.
We also want to have "alternate" collection weeks on
routes which will be faciliated by collections as well

commit b3a655c80225bc41c78bda8775649fbd90aa23db
Author: Chris Russo 
Date:   Mon Jul 6 14:18:54 2015 -0400

Add bcc module

Add to start archiving all emails in the system
to a specified email account
					

Step 4.5

Verify trees are exactly the same


CAR-computer:trc chris$ git cat-file -p 3706ca31771312646f0caf0356cbc9ee3b2f4533
tree f2f767cefda3d283f0fb3b68fd4f377e554b7f57
parent f79d6b54a3a7ee25cb391f0978abf85314113461
author Chris Russo <chris.andrews.russo@gmail.com> 1436206880 -0400
committer Chris Russo <chris.andrews.russo@gmail.com> 1436207673 -0400

Notify subscribers for missed collections

Add a template file for email copy
Add logic to cron to loop through and mail
users after they've not notified us
but have not left their bucket out

Remove old paypal templates and libraries
that aren't being used
					
Old Tree

Step 5

Push to shared repository

Pat yourself on the back... and head to ...

the drum circle

... and get your face painted ...

Fragments

Hit the next arrow...

... to step through ...

... a fragmented slide.

Fragment Styles

There's different types of fragments, like:

grow

shrink

fade-out

current-visible

highlight-red

highlight-blue

Speaker View

There's a speaker view. It includes a timer, preview of the upcoming slide as well as your speaker notes.

Press the S key to try it out.

Preguntas?!

We are

Savas Labs!


Follow us por favor! Yes, no, maybe?... Yes!
@Savas_Labs
Eh-tee-tee-pee double-u, double-u, double-u...
savaslabs.com/