The Problem:

git has a tremendous learning curve

Everyone learns commit/push/pull/branch and stops

Documentation is incredibly complex

git push

Updates remote refs using local refs, while sending objects necessary to complete the given refs.

The git's guide to git

git (n): British slang for "A stupid person"

"I've invented two things: Linux and git. Both were named after me" -- Linus Torvalds

What this talk is

  • Practical git advice
  • How to work with git on a team
  • Digging through git tools
(narcissistic self-promotion)

Terminology

  • SHA: the 'key' of a commit. Looks like
    ac31a31ca5b899f848aca4791cbca49fcbaa9a17
  • HEAD: The commit that you're currently looking at

Teamwork

Turns out programming is a team sport

Commit messages should:

  • Explain the how & why
  • Provide missing context
  • Point to external details
  • Encapsulate a single change

A Bad Commit Message


      commit 32f4410abb2a901016c4a8b23c4b487e36be9916
Author: Randall Koutnik <[email protected]>
Date:   Tue Jun 14 15:05:51 2016 -0700

    Fix error on alert page
    

A Good Commit Message

commit 6280ec89e3884e91da5c30faf8b4a55218bcac8b
Author: Igor Zhukov <[email protected]>
Date:   Thu Jun 30 00:46:43 2016 +0300

  fix(copy): fix handling of typed subarrays

  Previously, it would return a copy of the whole original typed array, not its slice.
  Now, the `byteOffset` and `length` are also preserved.

  Fixes #14842

  Closes #14845

Branching

  • Use small feature branches
  • Keep feature branches up-to-date
  • Never rewrite history on a pushed branch

Feature branches

Feature branches

Feature branches

Git Tools

git rebase

Allows you to mess with history in various exciting ways

Two main scenarios:

  • Bringing in new commits from master into your feature branch
  • Squashing multiple commits into a single commit

Merging

Rebasing

What's the big deal with history?

"Those without write access to history are doomed if they rebase it"

  • Rewriting history that's already on the remote breaks other dev's repos
  • Rewriting history that's only local is 'fine'

git log

Displays a list of all of the commits on the current branch

To the CLI!

git reflog

Lists all the commits you've looked at

Saves the day when a commit has been overridden and is no longer in regular history.

git reset

Updates the branch and/or code to another commit

Useful when you want to remove an accidental commit or when you realize you've been digging in the wrong rabbit hole

git cherry-pick

Takes a commit that exists somewhere locally and adds it to the current branch.

Great for pulling in a single commit from another branch without needing to do a full merge/rebase. Also nice for pulling things from reflog

git cherry-pick abc123

To the CLI!

git stash

Stores your current work without making a commit

Nice to have when you need to switch to another branch for some reason.

To the CLI!

Ok, now questions!

(I'm sure you have plenty)