$30 off During Our Annual Pro Sale. View Details »

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
    Will Save
    Your Life
    Wednesday, February 20, 13

    View Slide

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

    View Slide

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

    View Slide

  4. Wednesday, February 20, 13

    View Slide

  5. Wednesday, February 20, 13

    View Slide

  6. Wednesday, February 20, 13

    View Slide

  7. Wednesday, February 20, 13

    View Slide

  8. Wednesday, February 20, 13

    View Slide

  9. Wednesday, February 20, 13

    View Slide

  10. Wednesday, February 20, 13

    View Slide

  11. Wednesday, February 20, 13

    View Slide

  12. X
    Wednesday, February 20, 13

    View Slide

  13. X
    Revisions
    Wednesday, February 20, 13

    View Slide

  14. X
    Conflict
    Revisions
    Wednesday, February 20, 13

    View Slide

  15. ?
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  19. Versioning Tools
    CVS
    SVN
    TFS
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  32. Why Git?
    • It’s Offline
    • It’s Distributed
    • Branching & Merging is Easy
    • It’s Fast
    Wednesday, February 20, 13

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  38. NO
    Wednesday, February 20, 13

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  50. gitk
    Wednesday, February 20, 13

    View Slide

  51. git
    clients
    Wednesday, February 20, 13

    View Slide

  52. git
    clients
    Github for Mac
    Github for Win
    Tower
    Wednesday, February 20, 13

    View Slide

  53. Create &
    manage
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  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

    View Slide

  56. Untracked unmodified Modified staged
    Wednesday, February 20, 13

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  69. Seeing differences
    Wednesday, February 20, 13

    View Slide

  70. seeing differences
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  75. viewing history
    $ git status
    View the repository’s status
    View the log of commits
    $ git log
    Wednesday, February 20, 13

    View Slide

  76. Branches
    & Merging
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  78. Branches
    c3 c4
    c1 c2 c5
    Master
    head
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  80. head
    Branches
    c3 c4
    c1 c2 c5
    Master
    Wednesday, February 20, 13

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  91. --no-ff
    wtf?
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  93. plain merge
    Master
    Master
    Master Master
    MASTER MASTER
    Wednesday, February 20, 13

    View Slide

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

    View Slide

  95. Share?
    Wednesday, February 20, 13

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  103. git
    Hosts
    Github Bitbucket
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  105. github
    Wednesday, February 20, 13

    View Slide

  106. github
    Wednesday, February 20, 13

    View Slide

  107. github
    Wednesday, February 20, 13

    View Slide

  108. github
    Wednesday, February 20, 13

    View Slide

  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

    View Slide

  110. swag
    Wednesday, February 20, 13

    View Slide

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

    View Slide