Version Control Will Save Your Life

0478b7898ea85bd552d951ff167fd247?s=47 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

0478b7898ea85bd552d951ff167fd247?s=128

Dan Reedy

February 20, 2013
Tweet

Transcript

  1. Version Control Will Save Your Life Wednesday, February 20, 13

  2. daniel reedy Career Freelance Wednesday, February 20, 13

  3. Icon Credit: Thomas Le Bas, from The Noun Project Wednesday,

    February 20, 13
  4. Wednesday, February 20, 13

  5. Wednesday, February 20, 13

  6. Wednesday, February 20, 13

  7. Wednesday, February 20, 13

  8. Wednesday, February 20, 13

  9. Wednesday, February 20, 13

  10. Wednesday, February 20, 13

  11. Wednesday, February 20, 13

  12. X Wednesday, February 20, 13

  13. X Revisions Wednesday, February 20, 13

  14. X Conflict Revisions Wednesday, February 20, 13

  15. ? Wednesday, February 20, 13

  16. 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
  17. 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
  18. 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
  19. Versioning Tools CVS SVN TFS Wednesday, February 20, 13

  20. 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
  21. 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
  22. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  23. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  24. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  25. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  26. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  27. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  28. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  29. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  30. Central Repository Dan Adam Michele Rob Wednesday, February 20, 13

  31. git http://git-scm.org Wednesday, February 20, 13

  32. Why Git? • It’s Offline • It’s Distributed • Branching

    & Merging is Easy • It’s Fast Wednesday, February 20, 13
  33. Dan Adam Michele Rob Wednesday, February 20, 13

  34. Dan Adam Michele Rob Wednesday, February 20, 13

  35. Dan Adam Michele Rob Wednesday, February 20, 13

  36. Dan Adam Michele Rob Wednesday, February 20, 13

  37. Dan Adam Michele Rob Remote Repository Wednesday, February 20, 13

  38. NO Wednesday, February 20, 13

  39. well, sort of Wednesday, February 20, 13

  40. 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
  41. Dan Adam Michele Rob Wednesday, February 20, 13

  42. Dan Adam Michele Rob Remote Repository Wednesday, February 20, 13

  43. Dan Adam Rob Michele Blessed Repository Wednesday, February 20, 13

  44. Dan Adam Rob Michele Blessed Repository Wednesday, February 20, 13

  45. Dan Adam Rob Michele Blessed Repository Remote Repository Wednesday, February

    20, 13
  46. Dan Adam Rob Michele Blessed Repository Remote Repository Wednesday, February

    20, 13
  47. Dan Adam Rob Michele Blessed Repository Remote Repository Wednesday, February

    20, 13
  48. Dan Adam Rob Michele Blessed Repository Remote Repository www.housing.siu.edu Wednesday,

    February 20, 13
  49. 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
  50. gitk Wednesday, February 20, 13

  51. git clients Wednesday, February 20, 13

  52. git clients Github for Mac Github for Win Tower Wednesday,

    February 20, 13
  53. Create & manage Wednesday, February 20, 13

  54. 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
  55. 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
  56. Untracked unmodified Modified staged Wednesday, February 20, 13

  57. Untracked unmodified Modified staged Add the file Wednesday, February 20,

    13
  58. Untracked unmodified Modified staged Add the file edit the file

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

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

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

    Stage the file Commit the file remove from stage Wednesday, February 20, 13
  62. 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
  63. 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
  64. 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
  65. 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
  66. saving changes $ git diff View Differences between Files Commit

    staged files to the history $ git commit -m ‘We did things…’ Wednesday, February 20, 13
  67. 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
  68. 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
  69. Seeing differences Wednesday, February 20, 13

  70. seeing differences Wednesday, February 20, 13

  71. 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
  72. 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
  73. 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
  74. 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
  75. viewing history $ git status View the repository’s status View

    the log of commits $ git log Wednesday, February 20, 13
  76. Branches & Merging Wednesday, February 20, 13

  77. 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
  78. Branches c3 c4 c1 c2 c5 Master head Wednesday, February

    20, 13
  79. 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
  80. head Branches c3 c4 c1 c2 c5 Master Wednesday, February

    20, 13
  81. head Branches Master Master Wednesday, February 20, 13

  82. head Branches hotfix Master Master HOTFIX b r a n

    c h Wednesday, February 20, 13
  83. 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
  84. head Branches hotfix Master Master HOTFIX b r a n

    c h Wednesday, February 20, 13
  85. head Branches hotfix Master Master HOTFIX hotfix b r a

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

    r g e b r a n c h Wednesday, February 20, 13
  87. 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
  88. 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
  89. head Branches hotfix Master Master HOTFIX hotfix Master m e

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

    e r g e b r a n c h Wednesday, February 20, 13
  91. --no-ff wtf? Wednesday, February 20, 13

  92. 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
  93. plain merge Master Master Master Master MASTER MASTER Wednesday, February

    20, 13
  94. source: http://nvie.com/posts/a-successful-git-branching-model/ Time release branches master develop hot xes feature

    branches Wednesday, February 20, 13
  95. Share? Wednesday, February 20, 13

  96. Dan Adam Rob Michele Blessed Repository Remote Repository Wednesday, February

    20, 13
  97. 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
  98. 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
  99. 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
  100. 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
  101. 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
  102. 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
  103. git Hosts Github Bitbucket Wednesday, February 20, 13

  104. 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
  105. github Wednesday, February 20, 13

  106. github Wednesday, February 20, 13

  107. github Wednesday, February 20, 13

  108. github Wednesday, February 20, 13

  109. 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
  110. swag Wednesday, February 20, 13

  111. @ dan reedy.in Wednesday, February 20, 13