Slide 1

Slide 1 text

GIT, VERSION CONTROL, AND YOU. An introduction to the tastiest version control system. Ever. Courtesy of Jeff Byrnes [email protected] Monday, May 6, 13

Slide 2

Slide 2 text

WHATCHU TALKIN’ ’BOUT? • Who is this guy? • What is Git? • More importantly, what’s source control? • Why do I need it? • What makes Git so uber-sweet? And no so sweet? • Get the party started • Command me, o Git • Back to the Future • Branch me • Embracing conflict • More resources Monday, May 6, 13

Slide 3

Slide 3 text

WHO IS THIS GUY? • Jeff Byrnes • Web Developer (self-taught; HTML/CSS/PHP/JS) • Trained Musician (upright & electric bass) • Learned Git over the last year+, and now I’m here to share! Monday, May 6, 13

Slide 4

Slide 4 text

WHAT IS GIT? • A distributed version control system • Created by Linus Torvalds, the guy behind Linux • Used by lots of people, big to small (think Google, Twitter, etc.) • Especially popular amongst open-source projects • GitHub, anyone? jQuery, Linux, etc. Monday, May 6, 13

Slide 5

Slide 5 text

SOURCE CONTROL? • Ever heard of this website? Monday, May 6, 13

Slide 6

Slide 6 text

SOURCE CONTROL? • Source control is like a wiki for file changes • Lots of different systems (here’s three): • CVS • Subversion • Mercurial Monday, May 6, 13

Slide 7

Slide 7 text

SOURCE CONTROL? • Older systems (CVS, Subversion) are centralized • Network access is required • Everyone is dependent on the server Server Committer Committer Monday, May 6, 13

Slide 8

Slide 8 text

SOURCE CONTROL? • Git (and a few others) are distributed • This means every copy of the repository is a clone • So you can run off on your own & go nuts, or even push/ pull to each other Server Clone Clone Monday, May 6, 13

Slide 9

Slide 9 text

SOURCE CONTROL? • Well great, Jeff, but what if I’m a one-person operation? • I use DropBox, isn’t that like version control? Monday, May 6, 13

Slide 10

Slide 10 text

THE SWEET • A history of your changes • Line-by-line changes • Cheap branching • No server needed Monday, May 6, 13

Slide 11

Slide 11 text

THE NO-SO-SWEET • Not great for binary files (images, movies, etc.) • Lots to learn • Still very much a programmer’s tool out-of-the-box Monday, May 6, 13

Slide 12

Slide 12 text

GET THE PARTY STARTED • Install & identify yourself • Mac & Linux users: rejoice • Windows users: I’m sorry • git init • That’s it. Monday, May 6, 13

Slide 13

Slide 13 text

TERMS • repo • HEAD • commit • SHA1 or hash • ref • tree • index • working directory • remote Monday, May 6, 13

Slide 14

Slide 14 text

CONFIG • Global, per-user: • .gitconfig • Per-repository / folder • .gitattributes • .gitignore Monday, May 6, 13

Slide 15

Slide 15 text

AT YOUR COMMAND • git status • git add • git commit • git branch • git merge • git log • git push / git pull Monday, May 6, 13

Slide 16

Slide 16 text

GIT STATUS • Displays the state of your repository • Branch • Stages changes • Unstaged changes • Untracked files Monday, May 6, 13

Slide 17

Slide 17 text

GIT ADD • First step in creating a commit • Decides what does & doesn’t belong in a commit • Allows for fine-grained control, down to specific line additions/removals Monday, May 6, 13

Slide 18

Slide 18 text

GIT COMMIT • Create a commit • Commits everything staged using git add • Without arguments, opens your text editor to write a commit message • Or git add -m "Commit message" Monday, May 6, 13

Slide 19

Slide 19 text

BRANCH ME • A branch is a separate strand of work • Think features, bug fixes, flights of fancy • git checkout -b Monday, May 6, 13

Slide 20

Slide 20 text

GIT BRANCH • Where the fun starts • git branch lists branches • git branch • git branch -d Monday, May 6, 13

Slide 21

Slide 21 text

GIT MERGE • Brings a branch into the current HEAD • Many different merge types: • resolve • fast-forward • recursive • octopus • ours • subtree Monday, May 6, 13

Slide 22

Slide 22 text

EMBRACE CONFLICT (MERGES AREN’T SCARY) • Git is conservative • Git always defers to your judgment • Throws a merge conflict if it even thinks something is awry • GUI tools (e.g., Tower, Sourcetree, TortoiseGit, SmartGit) make merges way easier Monday, May 6, 13

Slide 23

Slide 23 text

GIT LOG • Shows the history of commits • Takes lots of fun arguments (read the man page) • Summary • List • Graph Monday, May 6, 13

Slide 24

Slide 24 text

GIT PUSH/PULL • Used to send or receive commits to/from a remote • git pull = git fetch + git merge • Used to distribute your changes Monday, May 6, 13

Slide 25

Slide 25 text

BACK TO THE FUTURE (THINK, MCFLY, THINK!) • Lots of ways to undo things • Here’s the two commands: • git revert • git reset Monday, May 6, 13

Slide 26

Slide 26 text

GIT REVERT • Reverses a single commit • Additions become deletions, deletions become additions • The reversion must then be committed Monday, May 6, 13

Slide 27

Slide 27 text

GIT RESET • Serious stuff. • Moves the HEAD back to a particular commit • Can become confusing if trying to reset a branch you’ve already pushed Monday, May 6, 13

Slide 28

Slide 28 text

ADVANCED COMMANDS • git rebase • git cherry-pick Monday, May 6, 13

Slide 29

Slide 29 text

GIT REBASE • Some advanced stuff now! • Used to stack your current commits on top of another branches changes • Can rebase remote as well as local branches • Rewrites history! Monday, May 6, 13

Slide 30

Slide 30 text

GIT CHERRY-PICK • Used to place a single commit from another branch into the current HEAD • Useful for applying commits like single patches • Best if used sparingly Monday, May 6, 13

Slide 31

Slide 31 text

PITFALLS • Large binary files • Tend to bloat the repo • Concepts can be complex • Directed acyclic graph…? • Very different from svn in some ways Monday, May 6, 13

Slide 32

Slide 32 text

DEPLOYMENTS • Many methods • Manual git pull • Hook scripts • Capistrano • Beanstalk • DeployHQ Monday, May 6, 13

Slide 33

Slide 33 text

DEALING WITH DATABASES • No real good way to do this • Create a repo & store a dump of the data & the schema • May not allow for diffs if the dump is binary • Old-school file backups! Monday, May 6, 13

Slide 34

Slide 34 text

CMS’S & GENERATED FILES • Generally speaking, don’t track generated files • User uploads • Logs • Sessions Monday, May 6, 13

Slide 35

Slide 35 text

GITHUB • Social coding • Repository host • Pages • Issues • Code Review • Gists Monday, May 6, 13

Slide 36

Slide 36 text

MORE RESOURCES • Git - git-scm.com • Git Book - book.git-scm.com • Successful branching model - nvie.com/posts/a-successful-git- branching-model/ • Git Ready - gitready.com • Get Started w/ Git - alistapart.com/articles/get-started-with-git/ • Git Reference - gitref.org • Think Like A Git - think-like-a-git.net • Interactive Git Cheatsheet - ndpsoftware.com/git-cheatsheet.html Monday, May 6, 13