git

what is code?

the symbolic arrangement of statements or instructions in a computer program, 
or the set of instructions in such a program

what is version control?

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

benefits

  • collaboration
  • understand what happened and why
  • safe experimentation
  • backup

what is git?

"git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency

why git?

  • all the cool kids use it
  • relatively easy to learn
  • tiny footprint
  • lightning fast
  • cheap local branching
  • convenient staging area
  • supports multiple workflows

a brief git history

https://upload.wikimedia.org/wikipedia/commons/3/3c/Sv-Linus_Torvalds2.ogg

Linus Torvalds

git commands

a few git commands

  • git init - initialize a new repository
  • git clone - copy a remote repository
  • git status - um, the status
  • git add - add files to the staging area
  • git commit - commit staged changes to the local repository
  • git log - see a history of commits
  • git remote - tell git where to find a remote repository
  • git pull - pull new commits from a remote repository
  • git push - copy local commits to a remote repository
  • git merge - bring commit histories together
  • git rebase - change the base commit of a branch

lots more

basic workflow

solo workflow

basics demo

👷🏼

visualizing

time

present

past

future

snapshot / commit

time

present

past

future

commits

branching

branching allows you to diverge from the main line

when to branch

  • branch when you want to work in isolation
    • feature
    • bug
    • experiment

in other words... often

feature/xyz

commits

master

commit

branching
strategies

workflow matters!

models

  • git flow
  • continuous integration
  • ...

git flow

http://nvie.com/posts/a-successful-git-branching-model/

strengths

  • well known
  • enables free experimentation
  • methodical and controlled
  • good code isolation

weaknesses

  • complex & prone to mistakes
  • encourages larger & less frequent releases
  • makes continuous integration more difficult

git flow

continuous integration model

master

feature/better-ness

bug/bad-thing

what if this happens...

instead of this?

conflict?

continuous integration model

strengths

  • still enables free experimentation
  • simple
  • encourages smaller & more frequent releases
  • accommodates continuous integration

weaknesses

  • good technical foundation required
    • testing
    • infrastructure

workflow with branching

branching workflow

branch and rebase demo

👷🏼

rebase!!

best practices

should I commit?

yes

🤔

should I push?

yes

🤔

should I branch?

yes

🤔

should I push to master?

NO!

🤔

anatomy of a good commit message

benefits of a good commit message

  • zero-effort release notes
  • faster code research
  • bragging rights

subject rules

  • subject is required & explains "what"
  • contained within a single line
    • 50 characters or less
    • hard limit at 72 characters
  • sentence case; no period at the end
  • use the imperative mood
    • fix, add, remove, refine, improve, refactor
  • subject should complete this sentence
    • if applied, this commit will...

https://chris.beams.io/posts/git-commit/

subject examples

Add .editorconfig

Update eslint settings to Facebook's recommended

Update dependency packages

Fix invalid mock nav data

Qualify loader names for webpack

Move eslint config into `.eslintrc.js`

body rules

  • optional but recommended in many cases
  • separated from the subject by a blank line
  • 72 characters per line
  • elaborate on "what" if needed
  • explain "why"
    • business reasons / developer logic, etc
  • don't explain how
    • the code diff explains how

########## RULES ############
# Capitalize the subject line
# Limit the subject line to 50 characters
# Do not end the subject line with a period
# Use the imperative mood in the subject line
# Separate subject from body with a blank line
# Wrap the body at 72 characters
# Use the body to explain what and why vs. how
#
##### SUBJECT ######
# Subject, 50 characters, 72 hard max ------50->|
# If you find it difficult to fit the subject into 50 characters --
# your commit is probably too big :-(
# Example imperative verbs: Fix, Add, Remove, Refine, Improve, Refactor
# If applied, this commit will...

 


##### DESCRIPTION #####
# Body, 72 characters so git can indent and stay under 80 --------72->|
# Elaborate what (if needed)
# Explain why (business reasons / developer logic, etc)
# Don’t explain how — code does that:

 

#
# Lines beginning with # are stripped from the git log

# git config --global commit.template ~/path/to/gitmessage.txt

parting words

  • we ❤️ git
  • the GUI tools are good
    • the command line is awesome 💥
  • branch, commit & push often
  • become a commit message artisan
  • we ❤️ the continuous integration model
  • keep it simple

git

By Bruce Campbell