Git going
    with    DVCS
               nutes oc
          90 mi ol magi f
    source code contr



                    by Matthew McCullough of Ambient Ideas, LLC
Matthew
McCullough
http://ambientideas.com/blog
http://presentationpatterns.com
http://orei.ly/ogitvid
http://www.wakaleo.com/books/continuous-
     integration-with-hudson-the-book
http://delicious.com/matthew.mccullough/git
Git
“Cool kids” version control system
Open Source
bash scripts   C code
≉
“ Git
 -noun                     asa nt
     ish Sla ng. an u nple
 Brit                      er son”
      cont   empt    ible p
 or
                       English D ictionar y
               -Oxford
otistical b astard, and
“
I'm an eg
    I name all my projects
    after myself. Fi rst Linux,


    now   git. ”
                     -Lin us Torvalds
Certified
Git User
145+ commands
18 used on
a daily basis
init     checkout   bisect

log      revert     clone

rebase   pack       diff

merge    pull       grep

commit   push       tag

add      status     branch
Distributed Version Control

        A new idea?
1997
code co-op
2001
 arch
2003
monotone
2003
 SVK
2003
 darcs
2005
bazaar
2005
mercurial
2005
 git
Why?
m s
                                                  ste
                                              l sy
                                           tro Subversion
                                        on
                                 n    c
                             rsio              Perforce

                           veSource
                       d
                                      Clear


                   ize        Safe
                                      Case


             a   l                    CVS
          t r               PVCS
    e n            RCS
C           Folders
“   hated it with a p assion...
    ...no w ay to do C VS right.
                -Linu s Torvalds
                                   ”
Why switch to
    Git
     ?
Safely Be Wrong

  Experiment
 Innovate
  Drive-by Assist

Crowd Source
and...
integration builds
integration builds
Hashes and Git
Index vs Hash


‣ Centralized VCS uses DB
  sequential index.
Index vs Hash


‣ Git uses SHA-1 hash.
40 hex characters
9AB223D28B1AA46EF1780B22F304982E39872C34
use as little of it as is unique
9AB223D28B1AA46EF1780B22F304982E39872C34
9AB223D28B1AA46EF1780B22F304982E39872C34
treeish
treeish = shorthand for hashes
9AB223
9AB223^
HEAD
HEAD^
HEAD~3
--since="2 weeks ago"
9AB223..56CD77
Hashable Objects

‣ Blob
‣ Tree
‣ Commit
‣ Tag
8d162
 c67db

   commit                                           7e8b1
                                                                                    blob
                                                                             7D 8D B3 7F BD 12 9F E9
                         a10b3
                                                            tree             7B 78 9D 3F 5C A6 72 CB
tree:
parent:
author:
              a10b3
              nil
              Fird
                                 tree              blob:    8d162 logo.jpg
committer:    Matthew                                                         51d22
                                                   blob:    51d22 draw.js
message:

Major refactoring
                        tree:
                        blob:
                                7e8b1 web
                                9ab16 index.html                                    blob
of the web content.                                                          //Some more javascript
                                                    9ab16                    var renderSize



                                                   <html>
                                                            blob
                                                          <body></body>
                                                   </html>
Distributed
connectivity
developer A
developer A   developer B
developer A   developer B
developer A   developer B
blessed repo




developer A                  developer B
Three Stage Thinking
Working         Staging       Repo

                 checkout

          add

                     commit


                                     Three stage thinking
Remote
Stash
                Repo




             Index
   Working
Remote
Stash
                Repo




             Index
   Working
Remote
Stash
                Repo
                       git clone




             Index
   Working
Remote
Stash
                Repo
                       git clone
                       git checkout




             Index
   Working
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files



             Index
   Working
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash

             Index
   Working
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash
                       test bug on master
             Index
                       working as designed



   Working
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash
                       test bug on master
             Index
                       working as designed

                       git stash apply
   Working
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash
                       test bug on master
             Index
                       working as designed

                       git stash apply
   Working             git add
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash
                       test bug on master
             Index
                       working as designed

                       git stash apply
   Working             git add
                       git commit
Remote
Stash
                Repo
                       git clone
                       git checkout
                       edit project files
                       boss interrupts
                       git stash
                       test bug on master
             Index
                       working as designed

                       git stash apply
   Working             git add
                       git commit
                       git push
WorkingOffline
More available connectivity
More available connectivity
More demand to work without
    connectivity
More demand to work without
    connectivity
Offline Anything
 Checkin
Offline Anything
 Checkin
 Add
 Branch
 List change log
 Grep history
 Rewrite history
 Stash
 Merge
 Label
 Remove
 practically everything but push
Offline Anything
 Checkin
 Add
 Branch
 List change log
 Grep history
 Rewrite history
 Stash
 Merge
 Label
 Remove
 practically everything but push
Matthew: Cool!
 Another commit to my
latest OSS project using
         Git!
Matthew: Cool!
             Another commit to my
            latest OSS project using
                     Git!



Madelaine: I like
  subversion
much better...
Storage Mechanics
Typical SCMs use deltas
v1       v2       v3       v4       v5
File A            File A            File A

File B   File B   File B   File B   File B

File C                     File C




                                             Storage
CVS / Subversion / darcs / Mercurial
Checkin
                           ckin




                                             kin
                  in




                                            Chec

                                                     kin
                        he
                ck




                                                      ec
                       C
              he
                                                                     in
         in




                                                   Ch
                   C
       ck                                                          k
            C he
                                                               h ec
      kin                                                  C
   ec
                                                                      ec kin
Delta storage gets slower as the hhistory
         Ch
                               C
 Checkin  of a file gets longer Checkin
Git uses Directed Acyclic Graph storage
                 (DAG)
cp -r srcfolder srcfolder.prev
Copy of the entire tree per checkin
zlib deflates every blob at commit
symlinks to existing identical blobs
v1       v2       v3       v4       v5
File A   File A   File A   File A   File A

File B   File B   File B   File B   File B

File C   File C   File C   File C   File C




                                             Storage
400MB Subversion repo
 convert to a 70MB Git repo
Speed
http://whygitisbetterthanx.com
Init               Add               Status               Diff
                                                                                      Branch (Cold/Hot)




git   hg     bzr   git   hg    bzr   git     hg     bzr   git   hg     bzr

      Tag                Log         Commit (Lg)          Commit (Sm)




                                                                             git c      git h    hg c     hg h     bzr c bzr h
git   hg     bzr   git   hg    bzr   git     hg     bzr   git   hg     bzr




                                                                                     data from http://whygitisbetterthanx.com/#git-is-fast
Init                              Status            Diff
                                                                                    Branch




git          svn                      git    svn    git          svn

      Tag                Log         Commit (Lg)   Commit (Sm)




                                                                           git c                    svn c
git          svn   git         svn    git    svn    git          svn




                                                                       data from http://whygitisbetterthanx.com/#git-is-fast
10
 to
     100 times
       Faster
Branch, Merge & Rebase
Branch
Cheap Branches


git branch newbranch
Merge
Merges lump branch changes into a
new unified commit
M
                 da
             S er
                   r
              ta g
                    d
                n e


Master/Trunk/MainLatest
                          a32
ard
    d
   n e
 ta g
                                     a32         Bra
                                                    n   ch
S er

           Master/Trunk/MainLatest
                                                             d19
   M                                 2e2


                                                             e69
                                     8b3

                                                    erge
                                                   M
                       d19           9f1   e69
Merge Anything


git merge --no-commit <sourcebranch>
Merge Anything


git merge --squash <sourcebranch>
Merge Anything


git merge <sourcebranch1> <sourcebranch2>
Rebase
Not a merge
simulates team members taking turns working
               (one person at a time)
Rebase for Clarity


git checkout myfeaturebranch
git rebase master
Rebasing


Master/Trunk/MainLatest
sing                             a32   Bra
                                              n   ch

 eba

           Master/Trunk/MainLatest
R                                    2e2               d19

                                     8b3
                                                       e69
Master/Trunk/MainLatest
                           a32

                    2e2

              8b3
             Bra
             ch n

       d19


e69




Rebase
Master/Trunk/MainLatest
                          a32

                   2e2

             8b3
           Bra
          ch  n
a32




Master/Trunk/MainLatest
                          2e2

                          8b3   Bra
                                   n   ch

                                            d19'


                                            e69'
Master/Trunk/MainLatest
                            a32

                     2e2

               8b3




e69'
        d19'
Who’s Got   Git?
UsageModels
Centralized
Central
 Repo
Centralized
Central
 Repo
Repo
               Blessed




Dictatorship
Repo
               Blessed




Dictatorship
Repo
               Blessed




Dictatorship
Repo
               Blessed




Dictatorship
Repo
               Blessed




Dictatorship
Certified




                         Integration Managed
           Development
 Repo         Repo
Certified




                         Integration Managed
           Development
 Repo         Repo
Certified




                         Integration Managed
           Development
 Repo         Repo
Certified




                         Integration Managed
           Development
 Repo         Repo
Private            Public




                   GitHub




Custom + Public Contrib
Private            Public




                   GitHub




Custom + Public Contrib
Private             Public




         Customized
                      GitHub




Custom + Public Contrib
Private             Public




         Customized
                      GitHub




Custom + Public Contrib
SVN Interop
arguably the best feature of git
use git in stealth mode
Subversion
git svn clone http://unfurl.com/trunk
//Hack, hack,   hack
git commit -a   -m‘Some changes’
git commit -a   -m‘More changes’
git commit -a   -m‘Final changes’
git svn dcommit
Subversion

‣ First class compatibility.
‣ Round trip support.
‣ Git commits = svn commits.
effortlessly convert full history
when ready to migrate the team
Migration

git svn clone http://unfurl.com/trunk
Migration

You now have a full git clone of the SVN repo
Migration

Power off your Subversion server
3
reasons
Cherry Pick



             !
‣git cherry-pick a5b2ee
‣Merge in just one commit.
Cherry Pick



             !
‣git cherry-pick a5b2ee
‣Merge in just one commit.
Search History



             "
‣git grep SomeText HEAD^^^
‣Search blob contents history without checkouts.
Search History



             "
‣git grep SomeText HEAD^^^
‣Search blob contents history without checkouts.
Bisect Bugs



                #
‣git bisect run mvn test
‣Binary-search for bug via failed tests.
‣Manual or automated modes.
‣Ant, Maven, or shell script that can return 0 or 1-127
Bisect Bugs



                #
‣git bisect run mvn test
‣Binary-search for bug via failed tests.
‣Manual or automated modes.
‣Ant, Maven, or shell script that can return 0 or 1-127
Twitter
 @matthewmccull             Matthew
Blog
 http://www.ambientideas.com/blog
         sidebar has all my social media links


Email
 matthewm@ambientideas.com
GitHub
 http://github.com/matthewmccullough
Image Credits
‣   http://www.ambientideasphotography.com
‣   http://flickr.com/photos/lenore-m/2903856664/
‣   http://en.wikipedia.org/wiki/Git_(software)
‣   http://flickr.com/photos/karenhorton/1583513014/
‣   http://flickr.com/photos/mashdnart/2545782407/
‣   http://commons.wikimedia.org/wiki/
    File:Small_Boy_nuclear_test_1962.jpg
‣   http://www.flickr.com/photos/knmurphy/2506896257/
‣   http://www.flickr.com/photos/albyspace/1022035568/
‣   http://flickr.com/photos/michaelhays/3070238360/
‣   http://flickr.com/photos/d_vdm/509996632/

Git Going with DVCS v1.6.0