Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git, Version Control, and You (v2)

Git, Version Control, and You (v2)

An updated version of my original deck on introducing folks to Git.

Jeff Byrnes

May 07, 2013
Tweet

More Decks by Jeff Byrnes

Other Decks in Programming

Transcript

  1. GIT, VERSION CONTROL, AND YOU. An introduction to the tastiest

    version control system. Ever. Courtesy of Jeff Byrnes [email protected] Monday, May 6, 13
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. THE SWEET • A history of your changes • Line-by-line

    changes • Cheap branching • No server needed Monday, May 6, 13
  10. 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
  11. 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
  12. TERMS • repo • HEAD • commit • SHA1 or

    hash • ref • tree • index • working directory • remote Monday, May 6, 13
  13. CONFIG • Global, per-user: • .gitconfig • Per-repository / folder

    • .gitattributes • .gitignore Monday, May 6, 13
  14. AT YOUR COMMAND • git status • git add •

    git commit • git branch • git merge • git log • git push / git pull Monday, May 6, 13
  15. GIT STATUS • Displays the state of your repository •

    Branch • Stages changes • Unstaged changes • Untracked files Monday, May 6, 13
  16. 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
  17. 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
  18. BRANCH ME • A branch is a separate strand of

    work • Think features, bug fixes, flights of fancy • git checkout -b <branchname> Monday, May 6, 13
  19. GIT BRANCH • Where the fun starts • git branch

    lists branches • git branch <branchname> • git branch -d <branchname> Monday, May 6, 13
  20. GIT MERGE • Brings a branch into the current HEAD

    • Many different merge types: • resolve • fast-forward • recursive • octopus • ours • subtree Monday, May 6, 13
  21. 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
  22. GIT LOG • Shows the history of commits • Takes

    lots of fun arguments (read the man page) • Summary • List • Graph Monday, May 6, 13
  23. 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
  24. 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
  25. GIT REVERT • Reverses a single commit • Additions become

    deletions, deletions become additions • The reversion must then be committed Monday, May 6, 13
  26. 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
  27. 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
  28. 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
  29. 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
  30. DEPLOYMENTS • Many methods • Manual git pull • Hook

    scripts • Capistrano • Beanstalk • DeployHQ Monday, May 6, 13
  31. 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
  32. CMS’S & GENERATED FILES • Generally speaking, don’t track generated

    files • User uploads • Logs • Sessions Monday, May 6, 13
  33. GITHUB • Social coding • Repository host • Pages •

    Issues • Code Review • Gists Monday, May 6, 13
  34. 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