Git 101
Scott Chacon
Introduction
Me
Scott Chacon
git-scm.com
http://progit.org
schacon@gmail.com
@chacon
  twitter
</me>
What is Git?
Git is an open source,
distributed version control
system designed for speed
        and efficiency
version control
mercurial (hg)

            bazaar

       subversion (svn)


version control
concurrent version system (cvs)

           ...
SoS
        mercurial (hg)

            bazaar

       subversion (svn)


version control
concurrent version system (cvs)
...
SoS
        mercurial (hg)      “not bad”

            bazaar

       subversion (svn)


version control
concurrent versio...
SoS
        mercurial (hg)

            bazaar

       subversion (svn)


version control
concurrent version system (cvs)
...
git           mercurial (hg)

                  bazaar

             subversion (svn)


      version control
      concur...
Git is an open source,
distributed version control
system designed for speed
       and efficiency
git-scm.com
Git is an open source,
distributed version control
 system designed for speed
        and efficiency
Fully Distributed
(almost) everything is local
which means

   everything is fast

every clone is a backup

     work offline
No Network Needed
         Performing a diff
        Viewing file history
       Committing changes
         Merging branch...
Git is an open source,
distributed version control
  system designed for
 speed and efficiency
Immutable
(almost) never removes data
Snapshots, not Patches
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
              



                        
 delta
storage
                             



       ...
Basic Git
First Steps
$ git config --global user.name “Scott Chacon”

$ git config --global user.email “schacon@gmail.com”
Getting a Repo
Create One
git init
$   touch hello_world.rb
$   git init
$   git add .
$   git commit -m ‘first commit’
$   touch hello_world.rb
$   git init
$   git add .
$   git commit -m ‘first commit’
$ tree -a
.
|-- .git
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks
|   |    |-- post-comm...
$ tree -a
.
|-- .git
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks
|   |    |-- post-comm...
$ tree -a
.
|-- .git
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks
|   |    |-- post-comm...
$   touch hello_world.rb
$   git init
$   git add .
$   git commit -m ‘first commit’
$   touch hello_world.rb
$   git init
$   git add .
$   git commit -m ‘first commit’
$ tree -a
.
|-- .git
|   |-- COMMIT_EDITMSG
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks...
$ tree -a
.
|-- .git
|   |-- COMMIT_EDITMSG
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks...
$ tree -a
.
|-- .git
|   |-- COMMIT_EDITMSG
|   |-- HEAD
|   |-- branches
|   |-- config
|   |-- description
|   |-- hooks...
Clone One
git clone
$ git clone git://github.com/schacon/ticgit.git
Initialized empty Git repository in /private/tmp/ticgit/.git/
remote: Coun...
$ git clone git://github.com/schacon/ticgit.git
Initialized empty Git repository in /private/tmp/ticgit/.git/
remote: Coun...
$ git clone git://github.com/schacon/ticgit.git
Initialized empty Git repository in /private/tmp/ticgit/.git/
remote: Coun...
$ git clone git://github.com/schacon/ticgit.git
Initialized empty Git repository in /private/tmp/ticgit/.git/
remote: Coun...
A Basic Workflow
A Basic Workflow
     Edit files
 Stage the changes
Review your changes
Commit the changes
working directory

git add
            index

                       git commit
          repository
a working copy
      working directory
                           of your project
git add
            index

             ...
working directory

         git add
                       index

                                  git commit

object dat...
working directory

git add
            index          “staging”
                       git commit
          repository
A Basic Workflow
     Edit files
 Stage the changes
Review your changes
Commit the changes
$ find .
./app.yaml
./index.yaml
./main.py
$ vim main.py
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp

class MainHandler(web...
$ vim main.py
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp

# this program prints...
$ git status
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what
#
#	modified:   mai...
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what
#
#	modified:   mai...
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what
#
#	modified:   mai...
$ git status
# On branch master
# Changed but not STAGED
                   updated:
#   (use "git add <file>..." to updat...
A Basic Workflow
     Edit files
 Stage the changes
Review your changes
Commit the changes
git add
working directory

git add
            index

                       git commit
          repository
working directory

git add
            index

                       git commit
          repository
$ git add main.py
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>.
#
#	modifie...
$ git add main.py
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>.
#
#	modifie...
$ git add main.py
$ git status
# On branch master
# Changes to be committed:
           THAT ARE STAGED
#    (use "git res...
$ vim app.yaml
application: chacon
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py
~
~
~
...
$ vim app.yaml
application: chacon
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py
~
~
~
...
$ vim app.yaml
application: chacon
version: 2
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py
~
~
~
...
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>..." to unstage)
#
#	 modified:...
$ vim main.py
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp

# this program prints...
$ vim main.py
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp

# this program prints...
$ vim main.py
#!/usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp

# this program prints...
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>..." to unstage)
#
#	 modified:...
$ git status
         # On branch master
         # Changes to be committed:
Staged   #    (use "git reset HEAD <file>..."...
$ git status
           # On branch master
           # Changes to be committed:
           #    (use "git reset HEAD <fil...
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>..." to unstage)
#
#	 modified:...
Staged                             In Working Directory
#!/usr/bin/env python                         #!/usr/bin/env pytho...
Staged                             In Working Directory
#!/usr/bin/env python                         #!/usr/bin/env pytho...
You have to stage a file
   after you edit it
You have to stage a file
  after you edit it
You have to stage a file
  after you edit it
$ git add app.yaml main.py
$ git status
# On branch master
# Changes to be committed:
#    (use "git reset HEAD <file>..."...
A Basic Workflow
     Edit files
 Stage the changes
Review your changes
Commit the changes
git commit
working directory

git add
            index

                       git commit
          repository
working directory

git add
            index

                       git commit
          repository
$ git commit

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty ...
$ git commit

descriptive commit message
# Please enter the commit message for your changes. Lines starting
# with '#' wil...
$ git commit

descriptive commit message
# Please enter the commit message for your changes. Lines starting
# with '#' wil...
$ git commit
Created commit 77d3001: descriptive commit message
 2 files changed, 4 insertions(+), 2 deletions(-)
A Basic Workflow
     Edit files        vim / emacs / etc
 Stage the changes      git add (file)
Review your changes     repo...
A Basic Workflow
     Edit files        vim / emacs / etc
 Stage the changes      git add (file)
Review your changes     repo...
A Basic Workflow
     Edit files        vim / emacs / etc
 Stage the changes      git add (file)
Review your changes     repo...
A Basic Workflow
     Edit files        vim / emacs / etc
 Stage the changes      git add (file)
Review your changes       gi...
A Basic Workflow
     Edit files        vim / emacs / etc
 Stage the changes      git add (file)
Review your changes       gi...
A Basicer Workflow

    Edit files      vim / emacs / etc
Stage and Commit    git commit -a
What’s going on here?
$ git commit
Created commit 77d3001: descriptive commit message
 2 files changed, 4 insertions(+), 2 deletions(-)
$ git commit
Created commit 77d3001: descriptive commit message
 2 files changed, 4 insertions(+), 2 deletions(-)
77d3001
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
                  ae668..
               commit               size
              ...
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
                   ae668..
                     commit        size
tree c4ec543b0...
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
                  ae668..
               commit               size
              ...
77d3001a1de6bf8f5e431972fe4d25b01e595c0b
                  ae668..
               commit                 size
            ...
ae668..
                              commit                 size
commit               size
  tree         2de54
         ...
ae668..
                                 commit                 size
commit                    size
  tree            2de5...
ae668..
                                                                                                   commit         ...
ae668..
                                                                                                   commit         ...
Repository

5b1   32a   c36

1d3   f46   3d4

ffe   6fe   ae6

38d   23f   03e

254   30e   5b1

a14   67e   1d3

3d5   73...
Repository

5b1   32a   c36

1d3   f46   3d4

ffe   6fe   ae6
                  git checkout ae635
38d   23f   03e

254   ...
Repository

5b1   32a   c36

1d3   f46   3d4

ffe   6fe   ae6
                  git checkout ae635
38d   23f   03e

254   ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository               Index               Working Directory

5b1   32a   c36
                    ./                3d4 ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
Repository             Index               Working Directory

5b1   32a   c36
                  ./                3d4     ...
object model
pointer to a       commit




                            }
 snapshot


                                C1
di...
object model
pointer to a       commit




                            }
 snapshot


                                C1
di...
ref




       commit                 commit                 commit




        tree                   tree               ...
Branching and Merging
branches
branches
lightweight, movable
pointers to a commit



      branch



        C1
branching
git branch
git checkout
HEAD



     default
     master         experiment




C0     C1




               C2      C3
HEAD


 C4
      default
      master       experiment




C3
C0       C5
        C1




              C2
      experiment...
HEAD


 C4
      default
      master       experiment




C3
C0       C5
        C1




              C2
      experiment...
HEAD


 C4
      default
      master       experiment


                           $ git branch
C3
C0       C5
        C1...
HEAD


 C4
      default
      master       experiment


                           $ git branch
C3
C0       C5
        C1...
C4
       default
       master      experiment




C3
C0        C5
         C1




              C2
      experiment     ...
T1          master
               default
               master              experiment


                                ...
T1          master
               default
               master              experiment


                                ...
T1          master
               default
               master              experiment


                                ...
T1          master
           default
           master               experiment


                                       ...
HEAD


                           T1
           default
           master               git checkout default
             ...
HEAD


                           T1
           default
           master               git checkout default
             ...
git commit
            T1              T1
                            master       default
                               ...
git commit
            T1              T1
                            master       default
                               ...
git commit
            T1              T1
                            master       default
                               ...
T1         default
                                          master




  C0        C1             C4




                ...
what is a branch, really?
$ find .git/refs
.git/refs
.git/refs/heads
.git/refs/heads/default
.git/refs/heads/experiment
$ find .git/refs
.git/refs
.git/refs/heads
.git/refs/heads/default
.git/refs/heads/experiment
$ find .git/refs
.git/refs
.git/refs/heads
.git/refs/heads/default
.git/refs/heads/experiment
$ find .git/refs
.git/refs
.git/refs/heads
.git/refs/heads/default
.git/refs/heads/experiment
$ cat .git/refs/heads/defaul...
$ find .git/refs
.git/refs
.git/refs/heads
.git/refs/heads/default
.git/refs/heads/experiment
$ cat .git/refs/heads/defaul...
$ cat .git/HEAD
ref: refs/heads/experiment
$ cat .git/HEAD
ref: refs/heads/experiment
$ cat .git/HEAD
ref: refs/heads/experiment
merging
git merge
T1         default
                               master




C0   C1         C4




          C2   C3           C5




   ...
HEAD



                            T1         default
                                       master




C0        C1     ...
HEAD



                             T1                master
                                               default




 ...
HEAD



                             T1                master
                                               default




 ...
default




 C0      C1                C4                 C6            C8




              C2      C3           C5      ...
default




C0        C1             C4         C6             C8




               C2   C3        C5             C7



 ...
HEAD


                                      default




C0     C1                   C4         C6             C8




    ...
HEAD


                                                   default




C0     C1                   C4        C6            ...
Why is this cool?
non-linear development
• clone the code that is in production
• create a branch for issue #53 (iss53)
• work for 10 minutes
• someone asks for a ...
production




origin/master      C1




                   C0



                             git clone
production




origin/master      C1        iss53




                   C0



                                     git ch...
iss53




                production   C2



origin/master      C1




                   C0



                          ...
iss53




                             C3



                production   C2



origin/master      C1




                ...
iss53




                             C3



                production   C2



origin/master      C1                     ...
iss53




                             C3      iss102




                production   C2       C4



origin/master      C...
iss53




                production   C3



   iss102          C4        C2



origin/master      C1




                ...
iss53




                production   C3



origin/master      C4        C2



                   C1




                ...
iss53




                             C5



                production   C3



origin/master      C4        C2



       ...
iss53




                                               C5



                production                     C3



origin...
iss53v2   iss53




                                        C5
                               C7



                produc...
try out an idea
isolate work units
long running topics
all local, so far
Remotes
sharing git
git clone git://github.com/schacon/simplegit2.git
distributed workflow
distributed workflow
     fetch, pull and push
fetch
pull
pull = fetch + merge
push
git push
a who in the what now?
local repo




           public repo                public repo




internet




                         local repo


  ...
local repo




               public repo                 public repo


           A   B   C

internet

                  ...
local repo



                   git fetch   A   B    C

                     (git)



               public repo         ...
local repo



                   git fetch   A   B    C

                     (git)     D   E    F   git commit



       ...
local repo



                   git fetch   A   B    C   git push
                     (git)     D   E    F    (ssh)



 ...
local repo



                   git fetch   A   B    C   git push
                     (git)     D   E    F    (ssh)



 ...
local repo



                   git fetch   A   B    C   git push
                     (git)     D   E    F    (ssh)



 ...
multiple remotes
developer                               developer
  nick                                   jessica




                   ...
developer                               developer
  nick                                   jessica




                   ...
developer                                developer
  nick                                    jessica




                 ...
developer                                developer
  nick                                    jessica




                 ...
developer                                       developer
  nick                                           jessica




   ...
ce0   4a7   5ec
developer                                                  developer
            e4a
  nick               ...
ce0   4a7   5ec
developer                                                  developer
            e4a
  nick               ...
ce0   4a7   5ec                                                 ce0   4a7   5ec
developer                                 ...
ce0   4a7   5ec                                                 ce0   4a7   5ec
developer                                 ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                 ce0   4a7   5ec
developer                                 ...
5ec                ce0   4a7   5ec                   ce0   4a7   5ec
      schacon/                        jessica/
      ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
nickh/                      schacon/                            jessic
                                          e4a      ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
 developer                                 ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
ce0   4a7   5ec                                                ce0   4a7   5ec
developer                                  ...
popular workflows
central repository
      model
developer             developer

developer                                     developer


                   shared repos...
shared repository




developer      developer        developer




            git clone
shared repository




developer      developer        developer




            git push
shared repository




developer      developer        developer




            git push
shared repository




developer      developer        developer
shared repository




developer       developer        developer




             git fetch
            git merge
shared repository




developer      developer        developer




            git push
dictator and lieutenants
         model
dictator                                 blessed repository




             lieutenant

lieutenant




developer         ...
dictator                                    blessed repository




             lieutenant

lieutenant




developer      ...
dictator                                 blessed repository




             lieutenant

lieutenant




developer         ...
dictator                                     blessed repository




             lieutenant

lieutenant




developer     ...
git fetch; git merge
  dictator                                 blessed repository




              lieutenant

 lieutena...
git push
 dictator                                 blessed repository




             lieutenant

lieutenant




develope...
dictator                                    blessed repository




             lieutenant

lieutenant




developer      ...
integration manager
       model
blessed
repository    developer   developer
                public      public




integration   developer   developer
 ma...
github.com
/schacon/ticgit
    blessed
                     /yob/ticgit   /pope/ticgit
   repository         developer    ...
github.com
/schacon/ticgit                 “forks”
    blessed
                     /yob/ticgit        /pope/ticgit
   rep...
blessed
 repository    developer   developer
                 public      public




 integration   developer   developer
...
blessed
repository       developer   developer
                   public      public




integration      developer   deve...
blessed
repository      developer   developer
                  public      public




integration     developer   develop...
blessed
repository    developer     developer
                public        public




integration   developer     develop...
blessed
repository    developer    developer
                public       public




integration   developer    developer
...
blessed
repository     developer   developer
                 public      public




integration    developer   developer
...
blessed
 repository    developer   developer
                 public      public




 integration   developer   developer
...
Remotes Are Branches
scott   jessica




default




 C1




 C0
scott              jessica




default           scott/default        default




 C1                   C1




 C0        ...
scott                    jessica




default
            git clone   scott/default        default




 C1                 ...
scott              jessica




default           scott/default        default




 C1                   C1




 C0        ...
scott              jessica




default           scott/default        default




 C1                   C1




 C0        ...
scott              jessica


                                       default




                                        C4...
scott              jessica


                                       default




                                        C4...
scott              jessica


                                       default




                                        C4...
scott              jessica


default                                default




 C7                                     C4...
scott              jessica


default                                default




 C7                                     C4...
scott              jessica


default           scott/default        default




 C7                   C7                C4...
scott                     jessica


default   scott/default    default   experiment




 C7           C7            C4    ...
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Git 101 Presentation
Upcoming SlideShare
Loading in …5
×

Git 101 Presentation

17,586 views

Published on

The slides for my talk at Symfony Live conference in Paris

Git 101 Presentation

  1. 1. Git 101 Scott Chacon
  2. 2. Introduction
  3. 3. Me
  4. 4. Scott Chacon
  5. 5. git-scm.com
  6. 6. http://progit.org
  7. 7. schacon@gmail.com
  8. 8. @chacon twitter
  9. 9. </me>
  10. 10. What is Git?
  11. 11. Git is an open source, distributed version control system designed for speed and efficiency
  12. 12. version control
  13. 13. mercurial (hg) bazaar subversion (svn) version control concurrent version system (cvs) perforce visual source safe
  14. 14. SoS mercurial (hg) bazaar subversion (svn) version control concurrent version system (cvs) perforce visual source safe
  15. 15. SoS mercurial (hg) “not bad” bazaar subversion (svn) version control concurrent version system (cvs) perforce visual source safe
  16. 16. SoS mercurial (hg) bazaar subversion (svn) version control concurrent version system (cvs) perforce visual source safe “kill self”
  17. 17. git mercurial (hg) bazaar subversion (svn) version control concurrent version system (cvs) perforce visual source safe
  18. 18. Git is an open source, distributed version control system designed for speed and efficiency
  19. 19. git-scm.com
  20. 20. Git is an open source, distributed version control system designed for speed and efficiency
  21. 21. Fully Distributed
  22. 22. (almost) everything is local
  23. 23. which means everything is fast every clone is a backup work offline
  24. 24. No Network Needed Performing a diff Viewing file history Committing changes Merging branches Obtaining other revisions of a file Switching branches
  25. 25. Git is an open source, distributed version control system designed for speed and efficiency
  26. 26. Immutable
  27. 27. (almost) never removes data
  28. 28. Snapshots, not Patches
  29. 29.         delta storage             snapshot      storage          
  30. 30.         delta storage             snapshot      storage          
  31. 31.         delta storage             snapshot      storage          
  32. 32.         delta storage             snapshot      storage          
  33. 33.         delta storage             snapshot      storage          
  34. 34.         delta storage             snapshot      storage          
  35. 35.         delta storage             snapshot      storage          
  36. 36.         delta storage             snapshot      storage          
  37. 37.         delta storage             snapshot      storage          
  38. 38.         delta storage             snapshot      storage          
  39. 39.         delta storage             snapshot      storage          
  40. 40.         delta storage             snapshot      storage          
  41. 41.         delta storage             snapshot      storage          
  42. 42.         delta storage             snapshot      storage          
  43. 43.         delta storage             snapshot      storage          
  44. 44. Basic Git
  45. 45. First Steps
  46. 46. $ git config --global user.name “Scott Chacon” $ git config --global user.email “schacon@gmail.com”
  47. 47. Getting a Repo
  48. 48. Create One
  49. 49. git init
  50. 50. $ touch hello_world.rb $ git init $ git add . $ git commit -m ‘first commit’
  51. 51. $ touch hello_world.rb $ git init $ git add . $ git commit -m ‘first commit’
  52. 52. $ tree -a . |-- .git | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- post-commit.sample | | |-- post-receive.sample | | |-- ... | | |-- pre-rebase.sample | | `-- update.sample | |-- info | | `-- exclude | |-- objects | | |-- info | | `-- pack | |-- refs | | |-- heads | | `-- tags | `-- remotes `-- hello_world.rb 11 directories, 25 files
  53. 53. $ tree -a . |-- .git | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- post-commit.sample | | |-- post-receive.sample | | |-- ... | | |-- pre-rebase.sample | | `-- update.sample | |-- info | | `-- exclude | |-- objects | | |-- info | | `-- pack | |-- refs | | |-- heads | | `-- tags | `-- remotes `-- hello_world.rb 11 directories, 25 files
  54. 54. $ tree -a . |-- .git | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- post-commit.sample | | |-- post-receive.sample | | |-- ... | | |-- pre-rebase.sample | | `-- update.sample | |-- info | | `-- exclude | |-- objects | | |-- info | | `-- pack | |-- refs | | |-- heads | | `-- tags | `-- remotes `-- hello_world.rb 11 directories, 25 files
  55. 55. $ touch hello_world.rb $ git init $ git add . $ git commit -m ‘first commit’
  56. 56. $ touch hello_world.rb $ git init $ git add . $ git commit -m ‘first commit’
  57. 57. $ tree -a . |-- .git | |-- COMMIT_EDITMSG | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- applypatch-msg.sample | | `-- update.sample | |-- index | |-- info | | `-- exclude | |-- logs | | |-- HEAD | | `-- refs | | `-- heads | | `-- master | |-- objects | | |-- 32/09658ac8d80bc9726d3a33d77e3dfc5fe6035e | | |-- 53/9cd7886a627841d525a78d45cbc6396be20b41 | | |-- e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | | |-- info | | `-- pack | |-- refs | | |-- heads | | | `-- master | | `-- tags | `-- remotes `-- hello_world.rb 17 directories, 33 files
  58. 58. $ tree -a . |-- .git | |-- COMMIT_EDITMSG | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- applypatch-msg.sample | | `-- update.sample | |-- index | |-- info | | `-- exclude | |-- logs | | |-- HEAD | | `-- refs | | `-- heads | | `-- master | |-- objects | | |-- 32/09658ac8d80bc9726d3a33d77e3dfc5fe6035e | | |-- 53/9cd7886a627841d525a78d45cbc6396be20b41 | | |-- e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | | |-- info | | `-- pack | |-- refs | | |-- heads | | | `-- master | | `-- tags | `-- remotes `-- hello_world.rb 17 directories, 33 files
  59. 59. $ tree -a . |-- .git | |-- COMMIT_EDITMSG | |-- HEAD | |-- branches | |-- config | |-- description | |-- hooks | | |-- applypatch-msg.sample | | `-- update.sample | |-- index | |-- info | | `-- exclude | |-- logs | | |-- HEAD | | `-- refs | | `-- heads | | `-- master | |-- objects | | |-- 32/09658ac8d80bc9726d3a33d77e3dfc5fe6035e | | |-- 53/9cd7886a627841d525a78d45cbc6396be20b41 | | |-- e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | | |-- info | | `-- pack | |-- refs | | |-- heads | | | `-- master | | `-- tags | `-- remotes `-- hello_world.rb 17 directories, 33 files
  60. 60. Clone One
  61. 61. git clone
  62. 62. $ git clone git://github.com/schacon/ticgit.git Initialized empty Git repository in /private/tmp/ticgit/.git/ remote: Counting objects: 591, done. remote: Compressing objects: 100% (267/267), done. remote: Total 591 (delta 253), reused 587 (delta 252) Receiving objects: 100% (591/591), 73.05 KiB, done. Resolving deltas: 100% (253/253), done. $ cd ticgit/ $ ls LICENSE! ! Rakefile! examples! note! ! ticgit.gemspec README! ! bin! lib! spec ! ! $
  63. 63. $ git clone git://github.com/schacon/ticgit.git Initialized empty Git repository in /private/tmp/ticgit/.git/ remote: Counting objects: 591, done. remote: Compressing objects: 100% (267/267), done. remote: Total 591 (delta 253), reused 587 (delta 252) Receiving objects: 100% (591/591), 73.05 KiB, done. Resolving deltas: 100% (253/253), done. $ cd ticgit/ $ ls LICENSE! ! Rakefile! examples! note! ! ticgit.gemspec README! ! bin! lib! spec ! ! $
  64. 64. $ git clone git://github.com/schacon/ticgit.git Initialized empty Git repository in /private/tmp/ticgit/.git/ remote: Counting objects: 591, done. remote: Compressing objects: 100% (267/267), done. remote: Total 591 (delta 253), reused 587 (delta 252) Receiving objects: 100% (591/591), 73.05 KiB, done. Resolving deltas: 100% (253/253), done. $ cd ticgit/ $ ls LICENSE! ! Rakefile! examples! note! ! ticgit.gemspec README! ! bin! lib! spec ! ! $
  65. 65. $ git clone git://github.com/schacon/ticgit.git Initialized empty Git repository in /private/tmp/ticgit/.git/ remote: Counting objects: 591, done. remote: Compressing objects: 100% (267/267), done. remote: Total 591 (delta 253), reused 587 (delta 252) Receiving objects: 100% (591/591), 73.05 KiB, done. Resolving deltas: 100% (253/253), done. $ cd ticgit/ $ ls .git LICENSE! ! Rakefile! examples! note! ! ticgit.gemspec README!! bin!! lib!! spec $
  66. 66. A Basic Workflow
  67. 67. A Basic Workflow Edit files Stage the changes Review your changes Commit the changes
  68. 68. working directory git add index git commit repository
  69. 69. a working copy working directory of your project git add index git commit repository
  70. 70. working directory git add index git commit object database repository
  71. 71. working directory git add index “staging” git commit repository
  72. 72. A Basic Workflow Edit files Stage the changes Review your changes Commit the changes
  73. 73. $ find . ./app.yaml ./index.yaml ./main.py
  74. 74. $ vim main.py #!/usr/bin/env python import wsgiref.handlers from google.appengine.ext import webapp class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hello world!') def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main() ~ ~ "main.py" 16L, 402C
  75. 75. $ vim main.py #!/usr/bin/env python import wsgiref.handlers from google.appengine.ext import webapp # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hello world!') def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main() ~ ~ "main.py" 16L, 402C
  76. 76. $ git status
  77. 77. $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what # # modified: main.py # no changes added to commit (use "git add" an
  78. 78. $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what # # modified: main.py # no changes added to commit (use "git add" an
  79. 79. $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what # # modified: main.py # no changes added to commit (use "git add" an
  80. 80. $ git status # On branch master # Changed but not STAGED updated: # (use "git add <file>..." to update what # # modified: main.py # no changes added to commit (use "git add" an
  81. 81. A Basic Workflow Edit files Stage the changes Review your changes Commit the changes
  82. 82. git add
  83. 83. working directory git add index git commit repository
  84. 84. working directory git add index git commit repository
  85. 85. $ git add main.py $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>. # # modified: main.py #
  86. 86. $ git add main.py $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>. # # modified: main.py #
  87. 87. $ git add main.py $ git status # On branch master # Changes to be committed: THAT ARE STAGED # (use "git reset HEAD <file>. # # modified: main.py #
  88. 88. $ vim app.yaml application: chacon version: 1 runtime: python api_version: 1 handlers: - url: .* script: main.py ~ ~ ~ "app.yaml" 8L, 101C
  89. 89. $ vim app.yaml application: chacon version: 1 runtime: python api_version: 1 handlers: - url: .* script: main.py ~ ~ ~ "app.yaml" 8L, 101C
  90. 90. $ vim app.yaml application: chacon version: 2 runtime: python api_version: 1 handlers: - url: .* script: main.py ~ ~ ~ "app.yaml" 8L, 101C
  91. 91. $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: main.py # # Changed but not updated: # (use "git add <file>..." to update what will be com # # modified: app.yaml #
  92. 92. $ vim main.py #!/usr/bin/env python import wsgiref.handlers from google.appengine.ext import webapp # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hello world!') def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main() ~ ~ "main.py" 16L, 402C
  93. 93. $ vim main.py #!/usr/bin/env python import wsgiref.handlers from google.appengine.ext import webapp # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hola world!') def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main() ~ ~ "main.py" 16L, 402C
  94. 94. $ vim main.py #!/usr/bin/env python import wsgiref.handlers from google.appengine.ext import webapp # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hola Mundo!') def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main() ~ ~ "main.py" 16L, 402C
  95. 95. $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: main.py # # Changed but not updated: # (use "git add <file>..." to update what will be com # # modified: app.yaml # modified: main.py #
  96. 96. $ git status # On branch master # Changes to be committed: Staged # (use "git reset HEAD <file>..." to unstage) # # modified: main.py # # Changed but not updated: # (use "git add <file>..." to update what will be com # # modified: app.yaml # modified: main.py #
  97. 97. $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: main.py # # Changed but not updated: Unstaged # # (use "git add <file>..." to update what will be com # modified: app.yaml # modified: main.py #
  98. 98. $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: main.py # # Changed but not updated: # (use "git add <file>..." to update what will be com # # modified: app.yaml # modified: main.py #
  99. 99. Staged In Working Directory #!/usr/bin/env python #!/usr/bin/env python import wsgiref.handlers import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.ext import webapp # this program prints out ‘hello world’ # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): class MainHandler(webapp.RequestHandler): def get(self): def get(self): self.response.out.write('Hello World!') self.response.out.write('Hola Mundo!') def main(): def main(): application = webapp.WSGIApplication application = webapp.WSGIApplication ([('/' ([('/' debug=True) debug=True) wsgiref.handlers.CGIHandler().run wsgiref.handlers.CGIHandler().run (applicat (applicat if __name__ == '__main__': if __name__ == '__main__': main() main()
  100. 100. Staged In Working Directory #!/usr/bin/env python #!/usr/bin/env python import wsgiref.handlers import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.ext import webapp # this program prints out ‘hello world’ # this program prints out ‘hello world’ class MainHandler(webapp.RequestHandler): class MainHandler(webapp.RequestHandler): def get(self): def get(self): self.response.out.write('Hello World!') self.response.out.write('Hola Mundo!') def main(): def main(): application = webapp.WSGIApplication application = webapp.WSGIApplication ([('/' ([('/' debug=True) debug=True) wsgiref.handlers.CGIHandler().run wsgiref.handlers.CGIHandler().run (applicat (applicat if __name__ == '__main__': if __name__ == '__main__': main() main()
  101. 101. You have to stage a file after you edit it
  102. 102. You have to stage a file after you edit it
  103. 103. You have to stage a file after you edit it
  104. 104. $ git add app.yaml main.py $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: app.yaml # modified: main.py #
  105. 105. A Basic Workflow Edit files Stage the changes Review your changes Commit the changes
  106. 106. git commit
  107. 107. working directory git add index git commit repository
  108. 108. working directory git add index git commit repository
  109. 109. $ git commit # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: app.yaml # modified: main.py # ~ ~ ~ ~ ".git/COMMIT_EDITMSG" 10L, 279C
  110. 110. $ git commit descriptive commit message # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: app.yaml # modified: main.py # ~ ~ ~ ~ ".git/COMMIT_EDITMSG" 10L, 279C
  111. 111. $ git commit descriptive commit message # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: app.yaml # modified: main.py # ~ ~ ~ ~ ".git/COMMIT_EDITMSG" 10L, 279C
  112. 112. $ git commit Created commit 77d3001: descriptive commit message 2 files changed, 4 insertions(+), 2 deletions(-)
  113. 113. A Basic Workflow Edit files vim / emacs / etc Stage the changes git add (file) Review your changes repo status Commit the changes git commit
  114. 114. A Basic Workflow Edit files vim / emacs / etc Stage the changes git add (file) Review your changes repo status Commit the changes git commit
  115. 115. A Basic Workflow Edit files vim / emacs / etc Stage the changes git add (file) Review your changes repo status Commit the changes git commit
  116. 116. A Basic Workflow Edit files vim / emacs / etc Stage the changes git add (file) Review your changes git status Commit the changes git commit
  117. 117. A Basic Workflow Edit files vim / emacs / etc Stage the changes git add (file) Review your changes git status Commit the changes git commit
  118. 118. A Basicer Workflow Edit files vim / emacs / etc Stage and Commit git commit -a
  119. 119. What’s going on here?
  120. 120. $ git commit Created commit 77d3001: descriptive commit message 2 files changed, 4 insertions(+), 2 deletions(-)
  121. 121. $ git commit Created commit 77d3001: descriptive commit message 2 files changed, 4 insertions(+), 2 deletions(-)
  122. 122. 77d3001
  123. 123. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b
  124. 124. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b
  125. 125. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b ae668.. commit size tree c4ec5 parent a149e author Scott committer Scott my commit message goes here and it is really, really cool
  126. 126. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b ae668.. commit size tree c4ec543b0322744e55c5efc9b6c4e449d398dbff parent a149e2160b3f7573768cdc2fce24d0881f3577e1 tree c4ec5 author Scott Chacon <schacon@gmail.com> 1223402504 -0700 committer Scott Chaconparent <schacon@gmail.com> 1223402504 -0700 a149e author Scott descriptive commit message committer Scott my commit message goes here and it is really, really cool
  127. 127. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b ae668.. commit size tree c4ec5 parent a149e author Scott committer Scott my commit message goes here and it is really, really cool
  128. 128. 77d3001a1de6bf8f5e431972fe4d25b01e595c0b ae668.. commit size tree c4ec5 parent a149e author Scott committer Scott my commit message goes here and it is really, really cool ./ c4e app.yaml 3d5 index.yaml 1d3 main.py 03e
  129. 129. ae668.. commit size commit size tree 2de54 tree c4ec5 parent 38def parent a149e author Scott author Scott committer Scott this is the previous commit committer Scott and I am very proud of it my commit message goes here and it is really, really cool ./ c4e app.yaml 3d5 index.yaml 1d3 main.py 03e
  130. 130. ae668.. commit size commit size tree 2de54 tree c4ec5 parent 38def parent a149e author Scott author Scott committer Scott this is the previous commit committer Scott and I am very proud of it my commit message goes here and it is really, really cool ./ c4e app.yaml 3d5 index.yaml 1d3 ./ c4e main.py 03e app.yaml 3d5 index.yaml 1d3 main.py 03e
  131. 131. ae668.. commit size commit size commit size commit size tree 2de54 tree c4ec5 tree 2fe65 tree parent author 2fe65 90ecd parent 90ecd parent 38def parent a149e Scott author Scott author author committer Scott committer Scott this is the commit before that and I'm not sure why Scott Scott this is the commit before that and I'm not sure why committer Scott this is the previous commit committer Scott and I am very proud of it ./ c4e app.yaml 3d5 my commit message goes here ./ c4e index.yaml 1d3 and it is really, really cool app.yaml 3d5 main.py 03e index.yaml 1d3 ./ c4e main.py 03e app.yaml 3d5 index.yaml 1d3 ./ c4e main.py 03e app.yaml 3d5 index.yaml 1d3 main.py 03e
  132. 132. ae668.. commit size commit size commit size commit size tree 2de54 tree c4ec5 tree 2fe65 tree parent author 48e 2fe65 90ecd parent 38d 90ecd parent a14 38def parent 77d a149e Scott author Scott author author committer Scott committer Scott this is the commit before that and I'm not sure why Scott Scott this is the commit before that and I'm not sure why committer Scott this is the previous commit committer Scott and I am very proud of it ./ c4e 3d5 my commit message goes here 32a app.yaml c4e ./ index.yaml 1d3 and it is really, really cool app.yaml 3d5 main.py 03e index.yaml 5b1 1d3 c4e ./ f46 main.py 03e app.yaml 23f 3d5 index.yaml 30e 1d3 ./ c4e main.py 67e 03e app.yaml 3d5 index.yaml 1d3 main.py 03e 03e
  133. 133. Repository 5b1 32a c36 1d3 f46 3d4 ffe 6fe ae6 38d 23f 03e 254 30e 5b1 a14 67e 1d3 3d5 735 d23 c4e c4e 48e 77d de3 2d3
  134. 134. Repository 5b1 32a c36 1d3 f46 3d4 ffe 6fe ae6 git checkout ae635 38d 23f 03e 254 30e 5b1 a14 67e 1d3 3d5 735 d23 c4e c4e 48e 77d de3 2d3
  135. 135. Repository 5b1 32a c36 1d3 f46 3d4 ffe 6fe ae6 git checkout ae635 38d 23f 03e 254 30e 5b1 a14 67e 1d3 3d5 735 d23 c4e c4e 48e 77d de3 2d3
  136. 136. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3
  137. 137. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3
  138. 138. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3
  139. 139. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3
  140. 140. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3 git add
  141. 141. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 Rakefile 34f 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3 git add
  142. 142. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 34f Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3 34f 3da a08 ae9 git commit
  143. 143. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 34f Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3 34f 3da a08 ae9
  144. 144. Repository Index Working Directory 5b1 32a c36 ./ 3d4 ./ 1d3 f46 3d4 ffe 6fe ae6 ./Rakefile 1d3 34f Rakefile 38d 23f 03e ./README 03e README 254 30e 5b1 a14 67e 1d3 ./lib/ c36 lib/ 3d5 735 d23 c4e c4e 48e ./lib/simplegit.rb 5b1 simplegit.rb 77d de3 2d3 34f 3da a08 ae9
  145. 145. object model pointer to a commit } snapshot C1 directory list tree file contents blob
  146. 146. object model pointer to a commit } snapshot C1 directory list tree file contents blob
  147. 147. ref commit commit commit tree tree tree blob tree blob tree blob tree blob
  148. 148. Branching and Merging
  149. 149. branches
  150. 150. branches lightweight, movable pointers to a commit branch C1
  151. 151. branching
  152. 152. git branch
  153. 153. git checkout
  154. 154. HEAD default master experiment C0 C1 C2 C3
  155. 155. HEAD C4 default master experiment C3 C0 C5 C1 C2 experiment C3 git branch experiment
  156. 156. HEAD C4 default master experiment C3 C0 C5 C1 C2 experiment C3 git branch experiment
  157. 157. HEAD C4 default master experiment $ git branch C3 C0 C5 C1 * default experiment C2 experiment C3
  158. 158. HEAD C4 default master experiment $ git branch C3 C0 C5 C1 * default experiment C2 experiment C3
  159. 159. C4 default master experiment C3 C0 C5 C1 C2 experiment C3 HEAD git checkout experiment
  160. 160. T1 master default master experiment git commit C0 C4 C1 2 C3 C5 C2 C3 experiment HEAD
  161. 161. T1 master default master experiment git commit C0 C4 C1 2 C3 C5 C2 C3 experiment HEAD
  162. 162. T1 master default master experiment git commit C0 C4 C1 2 C3 C5 C2 C3 experiment HEAD
  163. 163. T1 master default master experiment git commit C1 C0 C1 C4 git commit C2 C3 C2 C5 C3 experiment HEAD
  164. 164. HEAD T1 default master git checkout default master experiment C1 C0 C1 C4 C2 C3 C2 C5 C3 experiment
  165. 165. HEAD T1 default master git checkout default master experiment C1 C0 C1 C4 C2 C3 C2 C5 C3 experiment
  166. 166. git commit T1 T1 master default master HEAD C1 C0 C1 C4 C4 C2 C3 C2 C5 C3 C5 experiment experiment
  167. 167. git commit T1 T1 master default master HEAD C1 C0 C1 C4 C4 C2 C3 C2 C5 C3 C5 experiment experiment
  168. 168. git commit T1 T1 master default master HEAD C1 C0 C1 C4 C4 C2 C3 C2 C5 C3 C5 experiment experiment
  169. 169. T1 default master C0 C1 C4 C2 C3 C5 git checkout experiment experiment git commit HEAD
  170. 170. what is a branch, really?
  171. 171. $ find .git/refs .git/refs .git/refs/heads .git/refs/heads/default .git/refs/heads/experiment
  172. 172. $ find .git/refs .git/refs .git/refs/heads .git/refs/heads/default .git/refs/heads/experiment
  173. 173. $ find .git/refs .git/refs .git/refs/heads .git/refs/heads/default .git/refs/heads/experiment
  174. 174. $ find .git/refs .git/refs .git/refs/heads .git/refs/heads/default .git/refs/heads/experiment $ cat .git/refs/heads/default 6370409dc9e38af91565082bdf93577ff555489e
  175. 175. $ find .git/refs .git/refs .git/refs/heads .git/refs/heads/default .git/refs/heads/experiment $ cat .git/refs/heads/default 6370409dc9e38af91565082bdf93577ff555489e $ cat .git/refs/heads/experiment 33ce13c2f0ed35775956f81191b01a644448dcfc
  176. 176. $ cat .git/HEAD ref: refs/heads/experiment
  177. 177. $ cat .git/HEAD ref: refs/heads/experiment
  178. 178. $ cat .git/HEAD ref: refs/heads/experiment
  179. 179. merging
  180. 180. git merge
  181. 181. T1 default master C0 C1 C4 C2 C3 C5 experiment HEAD
  182. 182. HEAD T1 default master C0 C1 C4 C2 C3 C5 git checkout default experiment
  183. 183. HEAD T1 master default C0 C1 C4 C6 C2 C3 C5 git checkout default experiment git merge experiment
  184. 184. HEAD T1 master default C0 C1 C4 C6 C2 C3 C5 git checkout default experiment git merge experiment
  185. 185. default C0 C1 C4 C6 C8 C2 C3 C5 C7 experiment git checkout experiment HEAD
  186. 186. default C0 C1 C4 C6 C8 C2 C3 C5 C7 experiment git commit HEAD
  187. 187. HEAD default C0 C1 C4 C6 C8 C2 C3 C5 C7 experiment git checkout default
  188. 188. HEAD default C0 C1 C4 C6 C8 C2 C3 C5 C7 experiment git merge experiment
  189. 189. Why is this cool?
  190. 190. non-linear development
  191. 191. • clone the code that is in production • create a branch for issue #53 (iss53) • work for 10 minutes • someone asks for a hotfix for issue #102 • checkout ‘production’ • create a branch (iss102) • fix the issue • checkout ‘production’, merge ‘iss102’ • push ‘production’ • checkout ‘iss53’ and keep working
  192. 192. production origin/master C1 C0 git clone
  193. 193. production origin/master C1 iss53 C0 git checkout -b iss53
  194. 194. iss53 production C2 origin/master C1 C0 git commit
  195. 195. iss53 C3 production C2 origin/master C1 C0 git commit
  196. 196. iss53 C3 production C2 origin/master C1 iss102 C0 git checkout production git checkout -b iss102
  197. 197. iss53 C3 iss102 production C2 C4 origin/master C1 C0 git commit
  198. 198. iss53 production C3 iss102 C4 C2 origin/master C1 C0 git checkout production git merge iss102
  199. 199. iss53 production C3 origin/master C4 C2 C1 C0 git push
  200. 200. iss53 C5 production C3 origin/master C4 C2 C1 C0 git checkout iss53 git commit
  201. 201. iss53 C5 production C3 origin/master C4 iss53v2 C2 C1 C0 git checkout production git checkout -b iss53v2
  202. 202. iss53v2 iss53 C5 C7 production C3 C6 origin/master C4 C2 C1 C0 git commit git commit
  203. 203. try out an idea
  204. 204. isolate work units
  205. 205. long running topics
  206. 206. all local, so far
  207. 207. Remotes
  208. 208. sharing git
  209. 209. git clone git://github.com/schacon/simplegit2.git
  210. 210. distributed workflow
  211. 211. distributed workflow fetch, pull and push
  212. 212. fetch
  213. 213. pull
  214. 214. pull = fetch + merge
  215. 215. push
  216. 216. git push
  217. 217. a who in the what now?
  218. 218. local repo public repo public repo internet local repo A B C
  219. 219. local repo public repo public repo A B C internet git push (ssh) local repo A B C
  220. 220. local repo git fetch A B C (git) public repo public repo A B C internet git push (ssh) local repo A B C
  221. 221. local repo git fetch A B C (git) D E F git commit public repo public repo A B C internet git push (ssh) local repo A B C
  222. 222. local repo git fetch A B C git push (git) D E F (ssh) public repo public repo A B C A B C internet D E F git push (ssh) local repo A B C
  223. 223. local repo git fetch A B C git push (git) D E F (ssh) public repo public repo A B C A B C internet D E F git push git fetch (ssh) (http) local repo A B C D E F
  224. 224. local repo git fetch A B C git push (git) D E F (ssh) public repo public repo A B C A B C internet D E F D E F git push git fetch (ssh) (http) local repo A B C D E F
  225. 225. multiple remotes
  226. 226. developer developer nick jessica ce0 4a7 5ec master my repo e4a
  227. 227. developer developer nick jessica commit ce0 4a7 5ec master my repo e4a
  228. 228. developer developer nick jessica tree ce0 4a7 5ec master my repo e4a
  229. 229. developer developer nick jessica blobs ce0 4a7 5ec master my repo e4a
  230. 230. developer developer nick jessica ce0 4a7 5ec schacon/ e4a project "public" git push public ce0 4a7 5ec master my repo e4a public/master
  231. 231. ce0 4a7 5ec developer developer e4a nick jessica git clone (url) ce0 4a7 5ec schacon/ e4a project "public" ce0 4a7 5ec master my repo e4a public/master
  232. 232. ce0 4a7 5ec developer developer e4a nick jessica 24f ec5 c12 git commit ce0 4a7 5ec schacon/ e4a project "public" ce0 4a7 5ec master my repo e4a public/master
  233. 233. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick 24f ec5 c12 git clone (url) jessica ce0 4a7 5ec schacon/ e4a project "public" ce0 4a7 5ec master my repo e4a public/master
  234. 234. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb git commit a09 ce0 4a7 5ec schacon/ e4a project "public" ce0 4a7 5ec master my repo e4a public/master
  235. 235. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb git push a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "public" a09 ce0 4a7 5ec master my repo e4a public/master
  236. 236. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" a09 ce0 4a7 5ec master my repo e4a public/master git remote add nicknick git://github.com/nickh/project.git git remote add git://github.com/nickh/project.git
  237. 237. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb “nick” "nick" "public" a09 ce0 4a7 5ec master my repo e4a public/master git remote add nicknick git://github.com/nickh/project.git git remote add git://github.com/nickh/project.git
  238. 238. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" "jess" a09 ce0 4a7 5ec master my repo e4a public/master git remote add add jess git://github.com/jessica/project.git git remote jess git://github.com/jessica/project.git
  239. 239. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" “jess” "jess" a09 ce0 4a7 5ec master my repo e4a public/master git remote add add jess git://github.com/jessica/project.git git remote jess git://github.com/jessica/project.git
  240. 240. 5ec ce0 4a7 5ec ce0 4a7 5ec schacon/ jessica/ e4a e4a project ce0 4a7 5ec project ce0 4a7 5ec c12 developer 4ea df7 2fb developer e4a e4a "public" nick "jess" a09 jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec master ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ my repo e4a public/master e4a e4a project project project 24f ec5 c12 nick/master 4ea df7 2fb "nick" "public" "jess" a09 git fetch nick ce0 4a7 5ec master my repo e4a public/master git fetch nick git remote add jess git://github.com/jessica/project.git
  241. 241. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" "jess" a09 ce0 4a7 5ec master my repo e4a public/master 24f ec5 c12 nick/master git fetch nick
  242. 242. nickh/ schacon/ jessic e4a e4a project project proje 24f ec5 c12 ce0 4a7 5ec ce0 4a7 5ec developer "nick" "public" developer "jess e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec master ce0 4a7 5ec ce0 4a7 5ec my repo e4a ce0 4a7 5ec public/ nickh/ schacon/ jessica/ e4a e4a 24f e4a ec5 c12 nick/ma project project project 24f ec5 c12 4ea 4ea df7 df7 2fb 2fb jess/ma "nick" "public" "jess" a09 a09 git fetch jess ce0 4a7 5ec master master my repo e4a public/master public/master 24f ec5 c12 nick/master git fetchnick git fetch jess git remote add jess git://github.com/jessica/project.git
  243. 243. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" "jess" a09 ce0 4a7 5ec master my repo e4a public/master 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 git fetch jess
  244. 244. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 4ea df7 2fb "nick" "public" "jess" a09 ce0 4a7 5ec my repo e4a public/master 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master git merge nick jess
  245. 245. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 24f ec5 c12 4ea df7 2fb "nick" "public" 4ea df7 2fb "jess" a09 a09 c63 b3b ce0 4a7 5ec my repo e4a 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master public/master git push public
  246. 246. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 24f ec5 c12 4ea df7 2fb "nick" "public" 4ea df7 2fb "jess" a09 a09 c63 b3b ce0 4a7 5ec my repo e4a 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master public/master
  247. 247. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 24f ec5 c12 4ea df7 2fb "nick" "public" 4ea df7 2fb "jess" a09 a09 c63 b3b ce0 4a7 5ec my repo e4a 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master public/master
  248. 248. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 24f ec5 c12 4ea df7 2fb "nick" "public" 4ea df7 2fb "jess" a09 a09 c63 b3b ce0 4a7 5ec my repo e4a 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master public/master
  249. 249. ce0 4a7 5ec ce0 4a7 5ec developer developer e4a e4a nick jessica 24f ec5 c12 4ea df7 2fb a09 ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec nickh/ schacon/ jessica/ e4a e4a e4a project project project 24f ec5 c12 24f ec5 c12 4ea df7 2fb "nick" "public" 4ea df7 2fb "jess" a09 a09 c63 b3b ce0 4a7 5ec my repo e4a 24f ec5 c12 nick/master 4ea df7 2fb jess/master a09 c63 b3b master public/master
  250. 250. popular workflows
  251. 251. central repository model
  252. 252. developer developer developer developer shared repository developer developer developer developer
  253. 253. shared repository developer developer developer git clone
  254. 254. shared repository developer developer developer git push
  255. 255. shared repository developer developer developer git push
  256. 256. shared repository developer developer developer
  257. 257. shared repository developer developer developer git fetch git merge
  258. 258. shared repository developer developer developer git push
  259. 259. dictator and lieutenants model
  260. 260. dictator blessed repository lieutenant lieutenant developer developer developer developer
  261. 261. dictator blessed repository lieutenant lieutenant developer developer developer developer git clone
  262. 262. dictator blessed repository lieutenant lieutenant developer developer developer developer git fetch git merge
  263. 263. dictator blessed repository lieutenant lieutenant developer developer developer developer git fetch git merge
  264. 264. git fetch; git merge dictator blessed repository lieutenant lieutenant developer developer developer developer
  265. 265. git push dictator blessed repository lieutenant lieutenant developer developer developer developer
  266. 266. dictator blessed repository lieutenant lieutenant developer developer developer developer git fetch
  267. 267. integration manager model
  268. 268. blessed repository developer developer public public integration developer developer manager private private
  269. 269. github.com /schacon/ticgit blessed /yob/ticgit /pope/ticgit repository developer developer public public integration developer developer manager private private
  270. 270. github.com /schacon/ticgit “forks” blessed /yob/ticgit /pope/ticgit repository developer developer public public integration developer developer manager private private
  271. 271. blessed repository developer developer public public integration developer developer manager private private git push
  272. 272. blessed repository developer developer public public integration developer developer manager private private git clone
  273. 273. blessed repository developer developer public public integration developer developer manager private private git push
  274. 274. blessed repository developer developer public public integration developer developer manager private private git fetch git merge
  275. 275. blessed repository developer developer public public integration developer developer manager private private git push
  276. 276. blessed repository developer developer public public integration developer developer manager private private git fetch git merge
  277. 277. blessed repository developer developer public public integration developer developer manager private private git push
  278. 278. Remotes Are Branches
  279. 279. scott jessica default C1 C0
  280. 280. scott jessica default scott/default default C1 C1 C0 C0
  281. 281. scott jessica default git clone scott/default default C1 C1 C0 C0
  282. 282. scott jessica default scott/default default C1 C1 C0 C0
  283. 283. scott jessica default scott/default default C1 C1 C0 C0
  284. 284. scott jessica default C4 C3 default scott/default C2 C1 C1 C0 C0
  285. 285. scott jessica default C4 C3 default scott/default C2 C1 C1 C0 C0
  286. 286. scott jessica default C4 C3 default scott/default C2 C1 C1 C0 C0
  287. 287. scott jessica default default C7 C4 C6 C3 C5 scott/default C2 C1 C1 C0 C0
  288. 288. scott jessica default default C7 C4 C6 C3 C5 scott/default C2 C1 C1 C0 C0
  289. 289. scott jessica default scott/default default C7 C7 C4 C6 C6 C3 C5 C5 C2 C1 C1 C0 C0
  290. 290. scott jessica default scott/default default experiment C7 C7 C4 C9 C6 C6 C3 C8 C5 C5 C2 C1 C1 C0 C0

×