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

Version Control Will Save Your Life

Dan Reedy
February 20, 2013

Version Control Will Save Your Life

An introduction to version control using Git. Presented at the SIU Carbondale Tech Dawgs student organization

Dan Reedy

February 20, 2013
Tweet

More Decks by Dan Reedy

Other Decks in Technology

Transcript

  1. Version Control The task of keeping a software system consisting

    of many versions and configurations well organized. source: http://dictionary.reference.com/browse/version control Wednesday, February 20, 13
  2. Why use It? • It’s a communication tool • You

    can safely share code • Your development is organized • Changes are tracked • Prevents overwriting past work Wednesday, February 20, 13
  3. Repository A code database used to enable the collaborative development

    of large projects by multiple engineers. source: http://www.termwiki.com/EN:SCM_repository Wednesday, February 20, 13
  4. Check-out The act of copying the latest revision of a

    file from the repository so that it can be modified. source: http://www.termwiki.com/EN:check_out Wednesday, February 20, 13
  5. Check-in The act of copying files back into the repository

    after changing them. Also known as a commit. source: http://www.termwiki.com/EN:check_in Wednesday, February 20, 13
  6. Why Git? • It’s Offline • It’s Distributed • Branching

    & Merging is Easy • It’s Fast Wednesday, February 20, 13
  7. Shared repos • Facilitates sharing • Typically, no local changes

    • Has been turned into a great web service (e.g. Github & Bitbucket) • Ultimately, not needed Wednesday, February 20, 13
  8. getting git • It’s FREE • Included in OSX (needs

    upgraded) • Download from http://git-scm.org • Installs command-line tools • Includes gitk a basic GUI browser Wednesday, February 20, 13
  9. Getting started $ cd group_project $ git init Creating a

    new repository Cloning an existing repository $ git clone git://github.com/danreedy/amalgamate.git Wednesday, February 20, 13
  10. Working directory The local copy of files within a repository

    that are being tracked for changes, additions, and deletion. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  11. Untracked unmodified Modified staged Add the file edit the file

    Stage the file Wednesday, February 20, 13
  12. Untracked unmodified Modified staged Add the file edit the file

    Stage the file Commit the file Wednesday, February 20, 13
  13. Untracked unmodified Modified staged Add the file edit the file

    Stage the file Commit the file remove from stage Wednesday, February 20, 13
  14. Untracked unmodified Modified staged Add the file Untrack file edit

    the file Stage the file Commit the file remove from stage Wednesday, February 20, 13
  15. Index (stage) The intermediate area where you define how a

    commit will be look, allowing you to select specific changes. source: http://thkoch2001.github.com/whygitisbetter Wednesday, February 20, 13
  16. Handling files $ git add readme.txt $ git add .

    Adding files to the index (stage) Removing a file from being tracked $ git rm old_file.txt Removing a file from the index (stage) $ git reset -- readme.txt Wednesday, February 20, 13
  17. Untracked unmodified Modified staged Add the file Untrack file edit

    the file Stage the file Commit the file remove from stage Wednesday, February 20, 13
  18. saving changes $ git diff View Differences between Files Commit

    staged files to the history $ git commit -m ‘We did things…’ Wednesday, February 20, 13
  19. commit A single point in the git history; the entire

    history of a project is represented as a set of interrelated commits. Also called a revision or version. Includes a message describing itself. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  20. Seeing differences $ git diff 0ee42611b30ee50379b5ec270bbca35ab54fa98a diff --git a/lib/amalgamate/unity.rb b/lib/amalgamate/unity.rb

    index c3d40d0..6e3df5f 100644 --- a/lib/amalgamate/unity.rb +++ b/lib/amalgamate/unity.rb @@ -21,16 +21,21 @@ module Amalgamate diff_hash = self.diff(master, slave) merge_values = diff_hash.reduce({}) do |memo, attribute_set| attribute, values = attribute_set - memo[attribute] = values[priority] || values[secondary] + memo[attribute] = values[priority].nil? ? values[secondary] : values[priority] memo end master.assign_attributes(merge_values) master.save if options[:save] != false && master.changed? + self.reassign_associations(master, slave, priority: Wednesday, February 20, 13
  21. project timeline c5 File 1:1 File 2:1 File 3:1 c2

    c3 c4 File 1:2 File 2:1 File 3:1 File 1:3 File 2:1 File 3:1 File 1:3 File 2:2 File 3:1 File 1:4 File 2:3 File 3:1 c1 Wednesday, February 20, 13
  22. project timeline c5 File 1:1 File 2:1 File 3:1 c2

    c3 c4 File 1:2 File 2:1 File 3:1 File 1:3 File 2:1 File 3:1 File 1:3 File 2:2 File 3:1 File 1:4 File 2:3 File 3:1 c1 Wednesday, February 20, 13
  23. project timeline c5 File 1:1 File 2:1 File 3:1 c2

    c3 c4 File 1:2 File 2:1 File 3:1 File 1:3 File 2:1 File 3:1 File 1:3 File 2:2 File 3:1 File 1:4 File 2:3 File 3:1 c1 Wednesday, February 20, 13
  24. project timeline c5 File 1:1 File 2:1 File 3:1 c2

    c3 c4 File 1:2 File 2:1 File 3:1 File 1:3 File 2:1 File 3:1 File 1:3 File 2:2 File 3:1 File 1:4 File 2:3 File 3:1 c1 Wednesday, February 20, 13
  25. viewing history $ git status View the repository’s status View

    the log of commits $ git log Wednesday, February 20, 13
  26. branch An active line of development within a repository. A

    repository can have many branches, but your working directory is only associated with the one that is checked out. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  27. head A named reference to the commit at the tip

    of a branch. Referring to HEAD means the tip of the checked out branch. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  28. head Branches hotfix Master Master HOTFIX b r a n

    c h Wednesday, February 20, 13
  29. branches $ git checkout -b hotfix Create a branch Delete

    a branch $ git branch -d hotfix Checkout an existing branch $ git checkout hotfix Wednesday, February 20, 13
  30. head Branches hotfix Master Master HOTFIX b r a n

    c h Wednesday, February 20, 13
  31. head Branches hotfix Master Master HOTFIX hotfix Master m e

    r g e b r a n c h Wednesday, February 20, 13
  32. MERGE To bring the contents of another branch (possibly from

    an external repository) into the current branch. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  33. merge $ git checkout master Step 1: Switch to the

    destination branch Step 2: Merge the branch $ git merge --no-ff hotfix Wednesday, February 20, 13
  34. head Branches hotfix Master Master HOTFIX hotfix Master m e

    r g e b r a n c h Wednesday, February 20, 13
  35. head Branches hotfix Master Master HOTFIX hotfix Master Master m

    e r g e b r a n c h Wednesday, February 20, 13
  36. No Fast-forward hotfix Master Master HOTFIX hotfix Master Master m

    e r g e b r a n c h Wednesday, February 20, 13
  37. unmodified Modified staged edit the file Stage the file Commit

    the file Icon Credit: Pieter J. Smits, from The Noun Project Wednesday, February 20, 13
  38. Remote PUSH FETCH unmodified Modified staged edit the file Stage

    the file Commit the file Icon Credit: Pieter J. Smits, from The Noun Project Wednesday, February 20, 13
  39. PUSH Updating existing files and adding any missing files from

    a local branch to a remote branch that is a direct ancestor source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  40. fetch Updating existing files and adding any missing files from

    a remote branch to a local branch, without merging. source: http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html Wednesday, February 20, 13
  41. sharing history $ git push origin Send changes to a

    remote repository Copy changes from a remote repository $ git fetch origin master Merge changes from remote repository $ git merge origin/master Wednesday, February 20, 13
  42. sharing history $ git fetch origin master Copy changes from

    a remote Merge changes from the remote $ git merge origin/master Copy & Merge changes from remote $ git pull origin master + = Wednesday, February 20, 13
  43. hosted git • Github • Free micro plan for students

    • http://github.com/edu • Bitbucket • Free unlimited plan for students • http://bitbucket.org • Both offer public and private repos Wednesday, February 20, 13
  44. thanks • Each of you for coming • Tom Imboden

    for the invite • The guys who work for me for putting up with my rants about version control • Dav Glass @davglass from Yahoo! for the swag Wednesday, February 20, 13