KEMBAR78
Quick Introduction to git | PDF
Distributed version control with git
— a brief introduction


Joel Krebs
Slides by Oscar Nierstrasz
Why git?
Bob
Bob
      Carol
Bob
        Carol




Alice
          Ted
Bob
                                 Carol




Alice
                                   Ted

        A recipe for disaster!
What is git?
> Distributed revision control system
> Originally developed by Linus Torvalds for the
  development of the Linux Kernel in 2005
> Focus on speed and efficiency
> Quite a unique design and therefore sometimes a bit
  scary and difficult to understand
The git object model
A “blob” is content under
 version control (a file)

          blob
You can have trees of blobs
    (directories of files)

            tree
 blob
            tree
 blob
           blob
A “commit” is a tree of blobs
     (a set of changes)

           commit


            tree
 blob
            tree
 blob
            blob
Most commits modify
                (or merge) earlier
                     commits
                      commit
       commit
                       tree

        tree
                       blob
blob
        tree
blob
        blob
You can “tag” an
interesting commit

        tag
                         commit
                commit
                          tree

                 tree
                          blob
      blob
                 tree
      blob
                 blob
A graph of commits
may belong to a branch   branch

    tag
                         commit
           commit
                          tree

            tree
                          blob
  blob
            tree
  blob
            blob
HEAD
  “HEAD “is the
  current branch
                   branch

  tag
                   commit
         commit
                    tree

          tree
                    blob
blob
          tree
blob
          blob
HEAD


                  branch


                  commit
     commit




Let’s focus on commits
     and branches
Basic git
Create a git repo
                    HEAD

                    master

                     C0
Tell git to “stage”
              changes
HEAD

master

 C0
HEAD

master   Commit your
          changes
 C1

 C0
Collaborating
John                           Jane


Local repo   Public repo   Local repo



                master


                 C1


                 C0
John                            Jane


Local repo   Public repo   Local repo



   master       master        master


    C1           C1            C1


    C0           C0            C0
John                            Jane


Local repo   Public repo   Local repo



   master       master        master


    C2           C1            C3


    C1           C0            C1


    C0                         C0
John                                   Jane


    Local repo          Public repo   Local repo



       master              master        master


        C2                  C1            C3


        C1                  C0            C1


        C0                                C0




(nothing new to pull)
John                            Jane


Local repo   Public repo   Local repo



   master       master        master


    C2           C2            C3


    C1           C1            C1


    C0           C0            C0
John                            Jane


Local repo   Public repo   Local repo



   master       master        master


    C2           C2            C3      C2


    C1           C1            C1


    C0           C0            C0
John                                Jane


Local repo    Public repo      Local repo



   master        master           master


    C2            C2               C4


    C1            C1               C3      C2


    C0            C0               C1


                                   C0




             NB: git pull = fetch + merge
John                               Jane


Local repo   Public repo      Local repo



   master       master           master


    C2           C4               C4


    C1           C3      C2       C3      C2


    C0           C1               C1


                 C0               C0
John                                   Jane


Local repo       Public repo      Local repo



   master           master           master


    C4               C4               C4


    C3      C2       C3      C2       C3      C2


    C1               C1               C1


    C0               C0               C0
Branching
and merging
“origin” refers to the
                    remote repo


   HEAD

   master

origin/master

     C1

     C0
HEAD

                master

origin/master    C2

                 C1

                 C0
HEAD
                         tryout
                master

origin/master    C2

                 C1

                 C0
HEAD

                          tryout
                master

origin/master    C2

                 C1      NB: git checkout –b … =
                            branch + checkout
                 C0
HEAD

                         tryout
                master
                          C3
origin/master    C2

                 C1

                 C0
HEAD

         tryout
master
          C3      C5
 C2
                       origin/master
 C1       C4      C6

 C0                    origin/idea
HEAD

              tryout

               C7
master
         C3    C5
 C2
                       origin/master
 C1      C4    C6

 C0                    origin/idea
tryout
HEAD
               C7
master
         C3    C5
 C2
                       origin/master
 C1      C4    C6

 C0                    origin/idea
HEAD
              tryout
master
               C7
 C8
         C3    C5
 C2
                       origin/master
 C1      C4    C6

 C0                    origin/idea
HEAD
                              tryout
                master
                               C7
origin/master    C8
                         C3    C5
                 C2

                 C1      C4    C6

                 C0                    origin/idea
Overview git workflow



               Remote repository
                  fetch               push
                          Local repository
        pull                          commit
               checkout      Index (cache)
               HEAD                   add
                Working directory
Getting started
First steps

> Follow instructions on P2 Blog for installation
> Send your ssh public key to joel.krebs@students.unibe.ch
> Create meaningful commits with according messages
> Hints that make your life easier:
  —Create a .gitignore file
  —Always pull before you push
  —Don’t panic when merge conflicts occur
More to git
More to git …



> Merging and mergetool
> Squashing commits when merging
> Resolving conflicts
> User authentication with ssh
> gitx and other graphical tools
> git configure — remembering your name
> git remote — multiple remote repos
> github — an open source public repo
> …
Resources



   http://git-scm.com/                  http://book.git-scm.com/index.html



                 http://gitready.com/



                                   https://github.com/




http://www.slideshare.net/chacon/getting-git             http://oreilly.com/
http://creativecommons.org/licenses/by-sa/3.0/

Quick Introduction to git

  • 1.
    Distributed version controlwith git — a brief introduction Joel Krebs Slides by Oscar Nierstrasz
  • 2.
  • 3.
  • 4.
    Bob Carol
  • 5.
    Bob Carol Alice Ted
  • 6.
    Bob Carol Alice Ted A recipe for disaster!
  • 7.
  • 8.
    > Distributed revisioncontrol system > Originally developed by Linus Torvalds for the development of the Linux Kernel in 2005 > Focus on speed and efficiency > Quite a unique design and therefore sometimes a bit scary and difficult to understand
  • 9.
  • 10.
    A “blob” iscontent under version control (a file) blob
  • 11.
    You can havetrees of blobs (directories of files) tree blob tree blob blob
  • 12.
    A “commit” isa tree of blobs (a set of changes) commit tree blob tree blob blob
  • 13.
    Most commits modify (or merge) earlier commits commit commit tree tree blob blob tree blob blob
  • 14.
    You can “tag”an interesting commit tag commit commit tree tree blob blob tree blob blob
  • 15.
    A graph ofcommits may belong to a branch branch tag commit commit tree tree blob blob tree blob blob
  • 16.
    HEAD “HEAD“is the current branch branch tag commit commit tree tree blob blob tree blob blob
  • 17.
    HEAD branch commit commit Let’s focus on commits and branches
  • 18.
  • 19.
    Create a gitrepo HEAD master C0
  • 20.
    Tell git to“stage” changes HEAD master C0
  • 21.
    HEAD master Commit your changes C1 C0
  • 22.
  • 23.
    John Jane Local repo Public repo Local repo master C1 C0
  • 24.
    John Jane Local repo Public repo Local repo master master master C1 C1 C1 C0 C0 C0
  • 25.
    John Jane Local repo Public repo Local repo master master master C2 C1 C3 C1 C0 C1 C0 C0
  • 26.
    John Jane Local repo Public repo Local repo master master master C2 C1 C3 C1 C0 C1 C0 C0 (nothing new to pull)
  • 27.
    John Jane Local repo Public repo Local repo master master master C2 C2 C3 C1 C1 C1 C0 C0 C0
  • 28.
    John Jane Local repo Public repo Local repo master master master C2 C2 C3 C2 C1 C1 C1 C0 C0 C0
  • 29.
    John Jane Local repo Public repo Local repo master master master C2 C2 C4 C1 C1 C3 C2 C0 C0 C1 C0 NB: git pull = fetch + merge
  • 30.
    John Jane Local repo Public repo Local repo master master master C2 C4 C4 C1 C3 C2 C3 C2 C0 C1 C1 C0 C0
  • 31.
    John Jane Local repo Public repo Local repo master master master C4 C4 C4 C3 C2 C3 C2 C3 C2 C1 C1 C1 C0 C0 C0
  • 32.
  • 33.
    “origin” refers tothe remote repo HEAD master origin/master C1 C0
  • 34.
    HEAD master origin/master C2 C1 C0
  • 35.
    HEAD tryout master origin/master C2 C1 C0
  • 36.
    HEAD tryout master origin/master C2 C1 NB: git checkout –b … = branch + checkout C0
  • 37.
    HEAD tryout master C3 origin/master C2 C1 C0
  • 38.
    HEAD tryout master C3 C5 C2 origin/master C1 C4 C6 C0 origin/idea
  • 39.
    HEAD tryout C7 master C3 C5 C2 origin/master C1 C4 C6 C0 origin/idea
  • 40.
    tryout HEAD C7 master C3 C5 C2 origin/master C1 C4 C6 C0 origin/idea
  • 41.
    HEAD tryout master C7 C8 C3 C5 C2 origin/master C1 C4 C6 C0 origin/idea
  • 42.
    HEAD tryout master C7 origin/master C8 C3 C5 C2 C1 C4 C6 C0 origin/idea
  • 43.
    Overview git workflow Remote repository fetch push Local repository pull commit checkout Index (cache) HEAD add Working directory
  • 44.
  • 45.
    First steps > Followinstructions on P2 Blog for installation > Send your ssh public key to joel.krebs@students.unibe.ch > Create meaningful commits with according messages > Hints that make your life easier: —Create a .gitignore file —Always pull before you push —Don’t panic when merge conflicts occur
  • 46.
  • 47.
    More to git… > Merging and mergetool > Squashing commits when merging > Resolving conflicts > User authentication with ssh > gitx and other graphical tools > git configure — remembering your name > git remote — multiple remote repos > github — an open source public repo > …
  • 48.
    Resources http://git-scm.com/ http://book.git-scm.com/index.html http://gitready.com/ https://github.com/ http://www.slideshare.net/chacon/getting-git http://oreilly.com/
  • 49.