An introduction to git

olberger
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end




                                An introduction to git

                                          Olivier Berger
                               olivier.berger@telecom-sudparis.eu




                                  2012-12-06
           Adapted from "git concepts simplified" by Sitaram Chamarty,
            sitaramc@gmail.com http://sitaramc.github.com/gcs/



                                                                                                              1 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


Why Git




      Because




                                                                                                              2 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


constructing a graph of commits




      Git is all about constructing a nice local graph before sharing
      it
          1    Do your mess locally
          2    Commit a nice chronology
          3    Rework the local graph til it’s beautiful
          4    Share with others in remote repos




                                                                                                              3 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


GUI tools : gitk




                                                                                                              4 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


GUI tools : Eclipse’s EGit




                                                                                                              5 / 52
introduction   basics     branches and tags   local and remote repos   the object store   advanced operations    end


the 4 git object types



               Git keeps all its data inside a special directory called .git at
               the top level of your repository.
               Somewhere in there is what we will simply call the object store
               (if you’re not comfortable with that phrase, pretend it’s some
               sort of database).
               Git knows about 4 types of objects:
                        blob – each file that you add to the repo is turned into a blob
                        object.
                        tree – each directory is turned into a tree object.
                        Obviously, a tree object can contain other tree objects and blob
                        objects, just like a directory can contain other directories and files.
                        commit – a commit is a snapshot of your working tree at a point in
                        time, although it contains a lot of other information also.
                        tag – we will see this type a bit later.



                                                                                                                6 / 52
introduction   basics     branches and tags      local and remote repos   the object store   advanced operations    end


what is a SHA

               A commit is uniquely identified by a 160-bit hex value (the ‘SHA’). This
               is computed from the tree, plus the following pieces of information:
                        the   SHA of the parent commit(s) – every commit except the very first one in the repo
                        has   at least one parent commit that the change is based upon.
                        the   commit message – what you type in the editor when you commit
                        the   author name/email/timestamp the committer name/email/timestamp
               (Actually, all 4 git objects types are identified by SHAs, but of course
               they’re computed differently for each object type. However, the SHAs of
               the other object types are not relevant to this discussion).
               In the end, as I said, it’s just a large, apparently random looking, number,
               which is actually a cryptographically-strong checksum. It’s usually written
               out as 40 hex digits.
               Humans are not expected to remember this number. For the purposes of
               this discussion, think of it as something similar to a memory address
               returned by malloc().
               It is also GLOBALLY unique! No commit in any repo anywhere in the
               world will have the same SHA. (It’s not a mathematical impossibility, but
               just so extremely improbable that we take it as fact. If you didn’t
               understand that, just take it on faith).
               An example SHA: a30236028b7ddd65f01321af42f904479eaff549
                                                                                                                   7 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


what is a repo




    A repository (‘repo’) is a graph of
    commits.




      In our figures, we represent SHAs with numbers for convenience.
      We also represent time going upward (bottom to top).


                                                                                                              8 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations    end


why are the arrows backward in your pictures?




               So why are the arrows pointing backward?
               Well. . . every commit knows what its parent commit is (as
               described in the “what is a SHA” section above).
               But it can’t know what its child commits are – they haven’t
               been made yet!
               Therefore a repo is like a single linked list. It cannot be a
               double linked list – this is because any change to the contents
               would change the SHA!




                                                                                                              9 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


working locally and committing to a repo



      Commiting to the repository (History) is a 2 step process :
          1    staging (only what’s necessary)
          2    committing (when it’s complete)




                                                                                                              10 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


atomic commits in ‘git gui’

      git gui allows you to stage individual lines or diff hunks, instead of all
      of a file’s hunks




                                                                                                              11 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


branch




           Traditionally, the top of a linked list
           has a name.
           That name is a BRANCH name.




                                                                                                              12 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


more than one branch




           Remember we said a repo is a
           GRAPH?
           Specifically, more than one child
           node may be pointing at the same
           parent node.
           In this case, each ‘leaf node’ is a
           branch, and will have a name.




                                                                                                              13 / 52
introduction     basics   branches and tags   local and remote repos   the object store   advanced operations     end


more than one parent commit (1/2)




               Well we can’t keep creating
               more branches without
               eventually merging them
               back.
               So let’s say feature X is
               now tested enough to be
               merged into the main
               branch, so you :
                 git merge feature_X




                                                                                                                14 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


more than one parent commit (2/2)




           At this point, it’s quite common to
           delete the feature branch, especially
           if you anticipate no more “large”
           changes.
           So you can run
               git branch -d feature_X




                                                                                                              15 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


current branch/checked out branch




           There is a notion of a ‘currently
           checked out’ branch.
           This is denoted by a special ref
           called HEAD.
           HEAD is a symbolic ref, which
           points to the ‘current branch’.




                                                                                                              16 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


committing




           When you make a new
           commit, the current branch
           moves.
           Technically, whatever branch
           HEAD is pointing to will
           move.




                                                                                                              17 / 52
introduction     basics   branches and tags   local and remote repos   the object store   advanced operations     end


naming non-leaf nodes (1/2)




               It’s not just ‘leaf’ nodes, but inner
               nodes can also have names.
               Recall the result of merging
               feature_X earlier (see the more
               than one parent commit section):
               At this point, you could leave
               feature_X as it is forever.
               Or you could delete the branch (as
               we showed in that section), in
               which case that label would simply
               disappear.


                                                                                                                18 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


naming non-leaf nodes (2/2)




           You can also continue to develop
           on the feature_X branch, further
           refining it with a view to once
           again merging it at some later
           point in time.




                                                                                                              19 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


tags




           More commonly, inner nodes are
           TAGS.




                                                                                                              20 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


the difference between branches and tags




           The main difference between a
           branch and a tag is branches move,
           tags don’t.
           When you make a commit with the
           “master” branch currently checked
           out, master will move to point to
           the new commit.




                                                                                                              21 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


cloning and sharing


      No more central repositories (unless by convention)




                                                                                                              22 / 52
introduction   basics    branches and tags   local and remote repos   the object store   advanced operations     end


what is a git URL?




               Git repos are accessed by providing a URL.
               There are typically 4 kinds of Git URLs:
                        ssh: like
                        ssh://[user@]host.xz[:port]/path/to/repo.git/
                        http: like
                        http[s]://host.xz[:port]/path/to/repo.git/
                        git: like
                        git://host.xz[:port]/path/to/repo.git/

               local dir: like
               file:///full/path/to/reponame
      (see man git-clone for all the allowed syntaxes for git URLs).


                                                                                                               23 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


what is a “remote”?




               A remote is a short name (like an alias) used to refer to a
               specific git repository.
               Instead of always saying
                        git fetch git://sitaramc/gitolite

               you can add that as a remote and use that short name instead
               of the long URL.
               For convenience, a ‘remote’ called origin is automatically
               created when you clone a repo, pointing to the repo you
               cloned from.




                                                                                                              24 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


remote branches




           Git is a distributed
           version control
           system.
           So when you clone
           someone’s repo, you
           get all the branches in
           that one.




                                                                                                              25 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


multiple remotes




   You can have
   several remotes.




                                                                                                              26 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


fetching and merging from another repo (1/2)




    Now let’s say Sita’s repo had a
    couple of new commits on its
    master, and you run :
        git fetch sitas-repo




                                                                                                              27 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


fetching and merging from another repo (2/2)




           Now you want to merge Sita’s
           master branch into yours.
           Since your master does not have
           any commits that Sita’s master
           doesn’t have (i.e., Sita’s master is
           like a superset of yours), running
               git merge sitas-repo/master

           will get you this:




                                                                                                              28 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


the object store




               Git stores all your data in an “object store”.
               There are 4 types of objects in this store: files (called “blobs”),
               trees (which are directories+files), commits, and tags.
               All objects are referenced by a 160-bit SHA.




                                                                                                              29 / 52
introduction   basics   branches and tags       local and remote repos   the object store   advanced operations     end


what is a repo (again)




               Earlier, we saw that a repo was a graph of commits.
               At the file system level, however, it is basically a directory
               called .git which looks somewhat like this
               $ ls -al .git
               total 40
               drwxrwxr-x 7 sitaram   sitaram   4096 Sep 14 18:54 ./
               drwx------ 3 sitaram   sitaram   4096 Sep 14 18:54 ../
               drwxrwxr-x 2 sitaram   sitaram   4096 Sep 14 18:54 branches/
               -rw-rw-r-- 1 sitaram   sitaram   92 Sep 14 18:54 config
               -rw-rw-r-- 1 sitaram   sitaram   73 Sep 14 18:54 description
               -rw-rw-r-- 1 sitaram   sitaram   23 Sep 14 18:54 HEAD
               drwxrwxr-x 2 sitaram   sitaram   4096 Sep 14 18:54 hooks/
               drwxrwxr-x 2 sitaram   sitaram   4096 Sep 14 18:54 info/
               drwxrwxr-x 4 sitaram   sitaram   4096 Sep 14 18:54 objects/
               drwxrwxr-x 4 sitaram   sitaram   4096 Sep 14 18:54 refs/




                                                                                                                  30 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


objects and branches/tags (1/4)




               The really, really important thing to understand is that the
               object store doesn’t care where the commit came from or what
               “branch” it was part of when it entered the object store.
               Once it’s there, it’s there!




                                                                                                              31 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


objects and branches/tags (2/4)



      The starting point is before you did a fetch.




      The next two figures are after git fetch sitas-repo and git
      merge sitas-repo/master, respectively.



                                                                                                              32 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


objects and branches/tags (3/4)




               git fetch sitas-repo




                                                                                                              33 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


objects and branches/tags (4/4)


               git merge sitas-repo/master




      All you did was move a pointer from one node to another.

                                                                                                              34 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


advanced operations




      We’ll now show some advanced operations with the aid of this
      same tree.




                                                                                                              35 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


merging (1/4)




      First, let’s do merging.
               The merge you saw earlier was what is called a “fast-forward”
               merge, because your local master did not have any commits
               that the remote branch you were merging did not have.
               In practice, this is rare, especially on an active project with
               many developers.
               So let’s see what that looks like.




                                                                                                              36 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


merging (2/4)




      The starting point is this:




                                                                                                              37 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


merging (3/4)




           Now, you made some
           changes on your local
           master.
           Meanwhile, sitas-repo
           has had some changes
           which you got by
           doing a fetch




                                                                                                              38 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


merging (4/4)




   When you
       git merge sitas-repo/master

   the end result will usually
   look like this:




                                                                                                              39 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


cherry-pick (1/3)




               A cherry-pick is not very commonly done – in well designed
               workflows it should actually be rare.
               However, it’s a good way to illustrate an important concept in
               git.
               We said before that a commit represents a certain set of files
               and directories, but since most commits have only one parent,
               you can think of a commit as representing a set of changes too.




                                                                                                              40 / 52
introduction     basics   branches and tags   local and remote repos   the object store   advanced operations     end


cherry-pick (2/3)




               Let’s say one of your
               collaborators (this mythical
               “Sita” again!) made a whole
               bunch of changes to his copy
               of the repo.
               You don’t like most of these
               changes, except one specific
               change which you would like
               to bring in to your repo.
               The starting point is this:



                                                                                                                41 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


cherry picking (3/3)

               git cherry-pick sitas-repo/master~1




    This results in the following commit
    graph.




                                                                                                              42 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


rebasing (1/5)




               Instead of merging, let’s say you wanted to rebase your
               commits on top of Sita’s commits.
               First of all, what is rebasing?
               It’s basically transplanting a series of changes from one point
               in the graph to another point.
               So if you guessed that a rebase was (in principle) a series of
               cherry-picks, you’d be pretty close, at least from a concept
               point.




                                                                                                              43 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


rebasing (2/5)




           So let’s use a similar example as in
           the merge example before, but
           instead of sitas-repo, the new
           commits are in origin (which is
           the “main” server for this project).
           You had your own commits, and
           you did a git fetch origin
           which brought in the latest commits
           from “origin”, so it looks like:




                                                                                                              44 / 52
introduction     basics   branches and tags   local and remote repos   the object store   advanced operations     end


rebasing (3/5)




               Now, instead of merging origin/master
               into your local master, you want to rebase
               your commits on top of origin/master.
               That is, you want to pretend your local
               changes were made after commit 13 on
               the origin.
               So you run
                     git rebase origin/master

               and this is the result:



                                                                                                                45 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


rebasing (4/5)




               Unlike cherry-pick, a rebase is quite often done in real life.
               Rebase also has some other forms.
               This form is one, but the most common is when a developer
               wants to re-arrange his own local commits in a more logical
               sequence before publishing/pushing them.




                                                                                                              46 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


rebasing (5/5)

      I often do the eqvt of changing this:




      where “22delta” is a minor fixup to “22”, into




      using
               git rebase -i

                                                                                                              47 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


non fast-forward merge (1/2)




      Here’s the starting point :




                                                                                                              48 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


non fast-forward merge (2/2)



               git merge --no-ff feature_X




                                                                                                              49 / 52
introduction   basics   branches and tags   local and remote repos   the object store   advanced operations     end


“A successful Git branching model”




                                                                                                              50 / 52
introduction   basics    branches and tags   local and remote repos   the object store   advanced operations     end


Resources




               git concepts simplified
               A Visual Git Reference
               git cheat sheet
               An introduction to git-svn for Subversion/SVK users and
               deserters
               pro git
               mémento git à 100%
               A successful Git branching model




                                                                                                               51 / 52
introduction    basics   branches and tags   local and remote repos   the object store   advanced operations     end


copyrights + license



      ©Copyright Sitaram Chamarty, sitaramc@gmail.com (for parts
      originally in git concepts simplified)
      ©Copyright Mark Lodato, lodatom@gmail.com (for parts from A
      Visual Git Reference)
      ©Copyright Vincent Driessen (for parts from A successful Git
      branching model)
      ©Copyright 2012 Olivier Berger + Institut Mines Télécom

               This documentation is provided under a Creative Commons
                      Attribution-NonCommercial-ShareAlike 3.0.
       Made with org-mode (under emacs, to generate beamer slides with inline
                                  dot graphs)




                                                                                                               52 / 52
1 of 52

Recommended

Generating Linked Data descriptions of Debian packages in the Debian PTS by
Generating Linked Data descriptions of Debian packages in the Debian PTSGenerating Linked Data descriptions of Debian packages in the Debian PTS
Generating Linked Data descriptions of Debian packages in the Debian PTSolberger
1.6K views17 slides
Git training v10 by
Git training v10Git training v10
Git training v10Skander Hamza
929 views64 slides
Git: a brief introduction by
Git: a brief introductionGit: a brief introduction
Git: a brief introductionRandal Schwartz
1.3K views64 slides
Basic Git Intro by
Basic Git IntroBasic Git Intro
Basic Git IntroYoad Snapir
6.3K views56 slides
Git and github 101 by
Git and github 101Git and github 101
Git and github 101Senthilkumar Gopal
1.4K views30 slides
Getting Git Right by
Getting Git RightGetting Git Right
Getting Git RightSven Peters
152.2K views184 slides

More Related Content

What's hot

Introduction to Git by
Introduction to GitIntroduction to Git
Introduction to GitRandal Schwartz
3.1K views343 slides
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3) by
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Ahmed El-Arabawy
896 views69 slides
Apache Flink Hands On by
Apache Flink Hands OnApache Flink Hands On
Apache Flink Hands OnRobert Metzger
7.7K views46 slides
Binary Packaging for HPC with Spack by
Binary Packaging for HPC with SpackBinary Packaging for HPC with Spack
Binary Packaging for HPC with Spackinside-BigData.com
846 views26 slides
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017 by
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017Codemotion
767 views62 slides
Git the Docs: A fun, hands-on introduction to version control by
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlBecky Todd
187 views109 slides

What's hot(20)

Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3) by Ahmed El-Arabawy
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy896 views
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017 by Codemotion
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
HTTP2 in action - Piet Van Dongen - Codemotion Amsterdam 2017
Codemotion767 views
Git the Docs: A fun, hands-on introduction to version control by Becky Todd
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
Becky Todd187 views
VCS for Teamwork - GIT Workshop by Anis Ahmad
VCS for Teamwork - GIT WorkshopVCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT Workshop
Anis Ahmad176 views
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose by Flink Forward
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-ComposeSimon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Flink Forward10.6K views
Capital onehadoopintro by Doug Chang
Capital onehadoopintroCapital onehadoopintro
Capital onehadoopintro
Doug Chang2K views
Composing Project Archetyps with SBT AutoPlugins by Mark Schaake
Composing Project Archetyps with SBT AutoPluginsComposing Project Archetyps with SBT AutoPlugins
Composing Project Archetyps with SBT AutoPlugins
Mark Schaake2.3K views
2017 jenkins world by Brent Laster
2017 jenkins world2017 jenkins world
2017 jenkins world
Brent Laster2.1K views
Modern Perl for the Unfrozen Paleolithic Perl Programmer by John Anderson
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
John Anderson3.9K views
What's new in FreeBSD 10 by Gleb Smirnoff
What's new in FreeBSD 10What's new in FreeBSD 10
What's new in FreeBSD 10
Gleb Smirnoff1.8K views
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces by KubeAcademy
KubeCon EU 2016: Kubernetes and the Potential for Higher Level InterfacesKubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
KubeCon EU 2016: Kubernetes and the Potential for Higher Level Interfaces
KubeAcademy607 views
Intro to git (one hour version) by Randal Schwartz
Intro to git (one hour version)Intro to git (one hour version)
Intro to git (one hour version)
Randal Schwartz2.7K views
Building applications with Serverless Framework and AWS Lambda by Fredrik Vraalsen
Building applications with Serverless Framework and AWS LambdaBuilding applications with Serverless Framework and AWS Lambda
Building applications with Serverless Framework and AWS Lambda
Fredrik Vraalsen374 views

Viewers also liked

Presentation distro recipes-2013 by
Presentation distro recipes-2013Presentation distro recipes-2013
Presentation distro recipes-2013olberger
1.7K views20 slides
Git techtalk by
Git techtalkGit techtalk
Git techtalkjoren de groof
938 views98 slides
CraftCamp for Students - Introduction to git by
CraftCamp for Students - Introduction to gitCraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to gitcraftworkz
733 views43 slides
Git for the win! by
Git for the win!Git for the win!
Git for the win!Denver Sessink
469 views36 slides
Introduction to Git by
Introduction to GitIntroduction to Git
Introduction to GitColin Su
1.8K views32 slides
Git - The Incomplete Introduction by
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introductionrschwietzke
5.9K views94 slides

Viewers also liked(11)

Presentation distro recipes-2013 by olberger
Presentation distro recipes-2013Presentation distro recipes-2013
Presentation distro recipes-2013
olberger1.7K views
CraftCamp for Students - Introduction to git by craftworkz
CraftCamp for Students - Introduction to gitCraftCamp for Students - Introduction to git
CraftCamp for Students - Introduction to git
craftworkz733 views
Introduction to Git by Colin Su
Introduction to GitIntroduction to Git
Introduction to Git
Colin Su1.8K views
Git - The Incomplete Introduction by rschwietzke
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
rschwietzke5.9K views
Introduction to Git by Lukas Fittl
Introduction to GitIntroduction to Git
Introduction to Git
Lukas Fittl6.5K views
Git 101 Presentation by Scott Chacon
Git 101 PresentationGit 101 Presentation
Git 101 Presentation
Scott Chacon17.5K views
Git 101: Git and GitHub for Beginners by HubSpot
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
HubSpot152.7K views
Quick Introduction to git by Joel Krebs
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
Joel Krebs24.9K views

Similar to An introduction to git

Advanced git by
Advanced gitAdvanced git
Advanced gitsatya sudheer
106 views24 slides
Git basics with notes by
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
462 views42 slides
Git 101 for Beginners by
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners Anurag Upadhaya
1.5K views55 slides
Demystifying git by
Demystifying git Demystifying git
Demystifying git Andrey Dyblenko
192 views20 slides
Git basic stanley hsiao 2010_12_15 by
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Chen-Han Hsiao
553 views35 slides
Introduction to Git for developers by
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developersDmitry Guyvoronsky
5K views61 slides

Similar to An introduction to git(20)

Git basic stanley hsiao 2010_12_15 by Chen-Han Hsiao
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15
Chen-Han Hsiao553 views
DHT2 - O Brother, Where Art Thou with Shyam Ranganathan by Gluster.org
DHT2 - O Brother, Where Art Thou with 	Shyam RanganathanDHT2 - O Brother, Where Art Thou with 	Shyam Ranganathan
DHT2 - O Brother, Where Art Thou with Shyam Ranganathan
Gluster.org502 views
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git by Nicola Costantino
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Nicola Costantino2.2K views
Git Presentation - Purple Scout AB Malmö by Emil Erlandsson
Git Presentation - Purple Scout AB MalmöGit Presentation - Purple Scout AB Malmö
Git Presentation - Purple Scout AB Malmö
Emil Erlandsson2.4K views
Git, from the beginning by James Aylett
Git, from the beginningGit, from the beginning
Git, from the beginning
James Aylett400 views

More from olberger

Interoperability of FLOSS forges; lessons from the COCLICO project, implement... by
Interoperability of FLOSS forges; lessons from the COCLICO project, implement...Interoperability of FLOSS forges; lessons from the COCLICO project, implement...
Interoperability of FLOSS forges; lessons from the COCLICO project, implement...olberger
964 views30 slides
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper... by
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...olberger
6.4K views28 slides
Presentation forges logicielles à mathrice by
Presentation forges logicielles à mathricePresentation forges logicielles à mathrice
Presentation forges logicielles à mathriceolberger
1.1K views26 slides
Jailbreaking the Forges : project export/import efforts by
Jailbreaking the Forges : project export/import effortsJailbreaking the Forges : project export/import efforts
Jailbreaking the Forges : project export/import effortsolberger
1.1K views27 slides
Bug tracking à grande échelle et interopérabilité des outils de développement... by
Bug tracking à grande échelle et interopérabilité des outils de développement...Bug tracking à grande échelle et interopérabilité des outils de développement...
Bug tracking à grande échelle et interopérabilité des outils de développement...olberger
2.3K views49 slides
OSLC (Open Services for Lifecycle Collaboration): standard ouvert pour l’int... by
OSLC (Open Services for Lifecycle Collaboration):  standard ouvert pour l’int...OSLC (Open Services for Lifecycle Collaboration):  standard ouvert pour l’int...
OSLC (Open Services for Lifecycle Collaboration): standard ouvert pour l’int...olberger
2K views26 slides

More from olberger(19)

Interoperability of FLOSS forges; lessons from the COCLICO project, implement... by olberger
Interoperability of FLOSS forges; lessons from the COCLICO project, implement...Interoperability of FLOSS forges; lessons from the COCLICO project, implement...
Interoperability of FLOSS forges; lessons from the COCLICO project, implement...
olberger964 views
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper... by olberger
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...
OSLC (Open Services for Lifecycle Collaboration): open standard for interoper...
olberger6.4K views
Presentation forges logicielles à mathrice by olberger
Presentation forges logicielles à mathricePresentation forges logicielles à mathrice
Presentation forges logicielles à mathrice
olberger1.1K views
Jailbreaking the Forges : project export/import efforts by olberger
Jailbreaking the Forges : project export/import effortsJailbreaking the Forges : project export/import efforts
Jailbreaking the Forges : project export/import efforts
olberger1.1K views
Bug tracking à grande échelle et interopérabilité des outils de développement... by olberger
Bug tracking à grande échelle et interopérabilité des outils de développement...Bug tracking à grande échelle et interopérabilité des outils de développement...
Bug tracking à grande échelle et interopérabilité des outils de développement...
olberger2.3K views
OSLC (Open Services for Lifecycle Collaboration): standard ouvert pour l’int... by olberger
OSLC (Open Services for Lifecycle Collaboration):  standard ouvert pour l’int...OSLC (Open Services for Lifecycle Collaboration):  standard ouvert pour l’int...
OSLC (Open Services for Lifecycle Collaboration): standard ouvert pour l’int...
olberger2K views
Presentation soc-fr-fossa by olberger
Presentation soc-fr-fossaPresentation soc-fr-fossa
Presentation soc-fr-fossa
olberger513 views
Bugs tracking at a large scale in the FLOSS ecosystem by olberger
Bugs tracking at a large scale in the FLOSS ecosystemBugs tracking at a large scale in the FLOSS ecosystem
Bugs tracking at a large scale in the FLOSS ecosystem
olberger2K views
Coclico project - Forges Interoperability (OWF 2010) by olberger
Coclico project - Forges Interoperability (OWF 2010)Coclico project - Forges Interoperability (OWF 2010)
Coclico project - Forges Interoperability (OWF 2010)
olberger1.6K views
Introduction aux logiciels libres by olberger
Introduction aux logiciels libresIntroduction aux logiciels libres
Introduction aux logiciels libres
olberger2.1K views
Bugtracking on the Web 2.5 by olberger
Bugtracking on the Web 2.5Bugtracking on the Web 2.5
Bugtracking on the Web 2.5
olberger764 views
Introduction aux logiciels libres by olberger
Introduction aux logiciels libresIntroduction aux logiciels libres
Introduction aux logiciels libres
olberger696 views
Weaving a Semantic Web across OSS repositories - a spotlight on bts-link, UDD... by olberger
Weaving a Semantic Web across OSS repositories - a spotlight on bts-link, UDD...Weaving a Semantic Web across OSS repositories - a spotlight on bts-link, UDD...
Weaving a Semantic Web across OSS repositories - a spotlight on bts-link, UDD...
olberger778 views
Introduction to bts-link by olberger
Introduction to bts-linkIntroduction to bts-link
Introduction to bts-link
olberger1.4K views
Visualizing contributions in a forge -Case study on PicoForge by olberger
Visualizing contributions in a forge -Case study on PicoForgeVisualizing contributions in a forge -Case study on PicoForge
Visualizing contributions in a forge -Case study on PicoForge
olberger587 views
Plate-formes pour le développement collaboratif des logiciels libres by olberger
Plate-formes pour le développement collaboratif des logiciels libresPlate-formes pour le développement collaboratif des logiciels libres
Plate-formes pour le développement collaboratif des logiciels libres
olberger973 views
Retour d'expérience sur la conduite d'un projet libre by olberger
Retour d'expérience sur la conduite d'un projet libreRetour d'expérience sur la conduite d'un projet libre
Retour d'expérience sur la conduite d'un projet libre
olberger3.3K views
Olpc France Presentation Sl2008 by olberger
Olpc France Presentation Sl2008Olpc France Presentation Sl2008
Olpc France Presentation Sl2008
olberger994 views
Collaboration avec des projets libres - enjeux, difficultés et bonnes pratiques by olberger
Collaboration avec des projets libres - enjeux, difficultés et bonnes pratiquesCollaboration avec des projets libres - enjeux, difficultés et bonnes pratiques
Collaboration avec des projets libres - enjeux, difficultés et bonnes pratiques
olberger672 views

Recently uploaded

Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
17 views1 slide
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
33 views29 slides
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc
72 views29 slides
Kyo - Functional Scala 2023.pdf by
Kyo - Functional Scala 2023.pdfKyo - Functional Scala 2023.pdf
Kyo - Functional Scala 2023.pdfFlavio W. Brasil
418 views92 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
69 views8 slides
Vertical User Stories by
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
17 views16 slides

Recently uploaded(20)

"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays33 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto13 views
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays17 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi139 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab23 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana17 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive

An introduction to git

  • 1. introduction basics branches and tags local and remote repos the object store advanced operations end An introduction to git Olivier Berger olivier.berger@telecom-sudparis.eu 2012-12-06 Adapted from "git concepts simplified" by Sitaram Chamarty, sitaramc@gmail.com http://sitaramc.github.com/gcs/ 1 / 52
  • 2. introduction basics branches and tags local and remote repos the object store advanced operations end Why Git Because 2 / 52
  • 3. introduction basics branches and tags local and remote repos the object store advanced operations end constructing a graph of commits Git is all about constructing a nice local graph before sharing it 1 Do your mess locally 2 Commit a nice chronology 3 Rework the local graph til it’s beautiful 4 Share with others in remote repos 3 / 52
  • 4. introduction basics branches and tags local and remote repos the object store advanced operations end GUI tools : gitk 4 / 52
  • 5. introduction basics branches and tags local and remote repos the object store advanced operations end GUI tools : Eclipse’s EGit 5 / 52
  • 6. introduction basics branches and tags local and remote repos the object store advanced operations end the 4 git object types Git keeps all its data inside a special directory called .git at the top level of your repository. Somewhere in there is what we will simply call the object store (if you’re not comfortable with that phrase, pretend it’s some sort of database). Git knows about 4 types of objects: blob – each file that you add to the repo is turned into a blob object. tree – each directory is turned into a tree object. Obviously, a tree object can contain other tree objects and blob objects, just like a directory can contain other directories and files. commit – a commit is a snapshot of your working tree at a point in time, although it contains a lot of other information also. tag – we will see this type a bit later. 6 / 52
  • 7. introduction basics branches and tags local and remote repos the object store advanced operations end what is a SHA A commit is uniquely identified by a 160-bit hex value (the ‘SHA’). This is computed from the tree, plus the following pieces of information: the SHA of the parent commit(s) – every commit except the very first one in the repo has at least one parent commit that the change is based upon. the commit message – what you type in the editor when you commit the author name/email/timestamp the committer name/email/timestamp (Actually, all 4 git objects types are identified by SHAs, but of course they’re computed differently for each object type. However, the SHAs of the other object types are not relevant to this discussion). In the end, as I said, it’s just a large, apparently random looking, number, which is actually a cryptographically-strong checksum. It’s usually written out as 40 hex digits. Humans are not expected to remember this number. For the purposes of this discussion, think of it as something similar to a memory address returned by malloc(). It is also GLOBALLY unique! No commit in any repo anywhere in the world will have the same SHA. (It’s not a mathematical impossibility, but just so extremely improbable that we take it as fact. If you didn’t understand that, just take it on faith). An example SHA: a30236028b7ddd65f01321af42f904479eaff549 7 / 52
  • 8. introduction basics branches and tags local and remote repos the object store advanced operations end what is a repo A repository (‘repo’) is a graph of commits. In our figures, we represent SHAs with numbers for convenience. We also represent time going upward (bottom to top). 8 / 52
  • 9. introduction basics branches and tags local and remote repos the object store advanced operations end why are the arrows backward in your pictures? So why are the arrows pointing backward? Well. . . every commit knows what its parent commit is (as described in the “what is a SHA” section above). But it can’t know what its child commits are – they haven’t been made yet! Therefore a repo is like a single linked list. It cannot be a double linked list – this is because any change to the contents would change the SHA! 9 / 52
  • 10. introduction basics branches and tags local and remote repos the object store advanced operations end working locally and committing to a repo Commiting to the repository (History) is a 2 step process : 1 staging (only what’s necessary) 2 committing (when it’s complete) 10 / 52
  • 11. introduction basics branches and tags local and remote repos the object store advanced operations end atomic commits in ‘git gui’ git gui allows you to stage individual lines or diff hunks, instead of all of a file’s hunks 11 / 52
  • 12. introduction basics branches and tags local and remote repos the object store advanced operations end branch Traditionally, the top of a linked list has a name. That name is a BRANCH name. 12 / 52
  • 13. introduction basics branches and tags local and remote repos the object store advanced operations end more than one branch Remember we said a repo is a GRAPH? Specifically, more than one child node may be pointing at the same parent node. In this case, each ‘leaf node’ is a branch, and will have a name. 13 / 52
  • 14. introduction basics branches and tags local and remote repos the object store advanced operations end more than one parent commit (1/2) Well we can’t keep creating more branches without eventually merging them back. So let’s say feature X is now tested enough to be merged into the main branch, so you : git merge feature_X 14 / 52
  • 15. introduction basics branches and tags local and remote repos the object store advanced operations end more than one parent commit (2/2) At this point, it’s quite common to delete the feature branch, especially if you anticipate no more “large” changes. So you can run git branch -d feature_X 15 / 52
  • 16. introduction basics branches and tags local and remote repos the object store advanced operations end current branch/checked out branch There is a notion of a ‘currently checked out’ branch. This is denoted by a special ref called HEAD. HEAD is a symbolic ref, which points to the ‘current branch’. 16 / 52
  • 17. introduction basics branches and tags local and remote repos the object store advanced operations end committing When you make a new commit, the current branch moves. Technically, whatever branch HEAD is pointing to will move. 17 / 52
  • 18. introduction basics branches and tags local and remote repos the object store advanced operations end naming non-leaf nodes (1/2) It’s not just ‘leaf’ nodes, but inner nodes can also have names. Recall the result of merging feature_X earlier (see the more than one parent commit section): At this point, you could leave feature_X as it is forever. Or you could delete the branch (as we showed in that section), in which case that label would simply disappear. 18 / 52
  • 19. introduction basics branches and tags local and remote repos the object store advanced operations end naming non-leaf nodes (2/2) You can also continue to develop on the feature_X branch, further refining it with a view to once again merging it at some later point in time. 19 / 52
  • 20. introduction basics branches and tags local and remote repos the object store advanced operations end tags More commonly, inner nodes are TAGS. 20 / 52
  • 21. introduction basics branches and tags local and remote repos the object store advanced operations end the difference between branches and tags The main difference between a branch and a tag is branches move, tags don’t. When you make a commit with the “master” branch currently checked out, master will move to point to the new commit. 21 / 52
  • 22. introduction basics branches and tags local and remote repos the object store advanced operations end cloning and sharing No more central repositories (unless by convention) 22 / 52
  • 23. introduction basics branches and tags local and remote repos the object store advanced operations end what is a git URL? Git repos are accessed by providing a URL. There are typically 4 kinds of Git URLs: ssh: like ssh://[user@]host.xz[:port]/path/to/repo.git/ http: like http[s]://host.xz[:port]/path/to/repo.git/ git: like git://host.xz[:port]/path/to/repo.git/ local dir: like file:///full/path/to/reponame (see man git-clone for all the allowed syntaxes for git URLs). 23 / 52
  • 24. introduction basics branches and tags local and remote repos the object store advanced operations end what is a “remote”? A remote is a short name (like an alias) used to refer to a specific git repository. Instead of always saying git fetch git://sitaramc/gitolite you can add that as a remote and use that short name instead of the long URL. For convenience, a ‘remote’ called origin is automatically created when you clone a repo, pointing to the repo you cloned from. 24 / 52
  • 25. introduction basics branches and tags local and remote repos the object store advanced operations end remote branches Git is a distributed version control system. So when you clone someone’s repo, you get all the branches in that one. 25 / 52
  • 26. introduction basics branches and tags local and remote repos the object store advanced operations end multiple remotes You can have several remotes. 26 / 52
  • 27. introduction basics branches and tags local and remote repos the object store advanced operations end fetching and merging from another repo (1/2) Now let’s say Sita’s repo had a couple of new commits on its master, and you run : git fetch sitas-repo 27 / 52
  • 28. introduction basics branches and tags local and remote repos the object store advanced operations end fetching and merging from another repo (2/2) Now you want to merge Sita’s master branch into yours. Since your master does not have any commits that Sita’s master doesn’t have (i.e., Sita’s master is like a superset of yours), running git merge sitas-repo/master will get you this: 28 / 52
  • 29. introduction basics branches and tags local and remote repos the object store advanced operations end the object store Git stores all your data in an “object store”. There are 4 types of objects in this store: files (called “blobs”), trees (which are directories+files), commits, and tags. All objects are referenced by a 160-bit SHA. 29 / 52
  • 30. introduction basics branches and tags local and remote repos the object store advanced operations end what is a repo (again) Earlier, we saw that a repo was a graph of commits. At the file system level, however, it is basically a directory called .git which looks somewhat like this $ ls -al .git total 40 drwxrwxr-x 7 sitaram sitaram 4096 Sep 14 18:54 ./ drwx------ 3 sitaram sitaram 4096 Sep 14 18:54 ../ drwxrwxr-x 2 sitaram sitaram 4096 Sep 14 18:54 branches/ -rw-rw-r-- 1 sitaram sitaram 92 Sep 14 18:54 config -rw-rw-r-- 1 sitaram sitaram 73 Sep 14 18:54 description -rw-rw-r-- 1 sitaram sitaram 23 Sep 14 18:54 HEAD drwxrwxr-x 2 sitaram sitaram 4096 Sep 14 18:54 hooks/ drwxrwxr-x 2 sitaram sitaram 4096 Sep 14 18:54 info/ drwxrwxr-x 4 sitaram sitaram 4096 Sep 14 18:54 objects/ drwxrwxr-x 4 sitaram sitaram 4096 Sep 14 18:54 refs/ 30 / 52
  • 31. introduction basics branches and tags local and remote repos the object store advanced operations end objects and branches/tags (1/4) The really, really important thing to understand is that the object store doesn’t care where the commit came from or what “branch” it was part of when it entered the object store. Once it’s there, it’s there! 31 / 52
  • 32. introduction basics branches and tags local and remote repos the object store advanced operations end objects and branches/tags (2/4) The starting point is before you did a fetch. The next two figures are after git fetch sitas-repo and git merge sitas-repo/master, respectively. 32 / 52
  • 33. introduction basics branches and tags local and remote repos the object store advanced operations end objects and branches/tags (3/4) git fetch sitas-repo 33 / 52
  • 34. introduction basics branches and tags local and remote repos the object store advanced operations end objects and branches/tags (4/4) git merge sitas-repo/master All you did was move a pointer from one node to another. 34 / 52
  • 35. introduction basics branches and tags local and remote repos the object store advanced operations end advanced operations We’ll now show some advanced operations with the aid of this same tree. 35 / 52
  • 36. introduction basics branches and tags local and remote repos the object store advanced operations end merging (1/4) First, let’s do merging. The merge you saw earlier was what is called a “fast-forward” merge, because your local master did not have any commits that the remote branch you were merging did not have. In practice, this is rare, especially on an active project with many developers. So let’s see what that looks like. 36 / 52
  • 37. introduction basics branches and tags local and remote repos the object store advanced operations end merging (2/4) The starting point is this: 37 / 52
  • 38. introduction basics branches and tags local and remote repos the object store advanced operations end merging (3/4) Now, you made some changes on your local master. Meanwhile, sitas-repo has had some changes which you got by doing a fetch 38 / 52
  • 39. introduction basics branches and tags local and remote repos the object store advanced operations end merging (4/4) When you git merge sitas-repo/master the end result will usually look like this: 39 / 52
  • 40. introduction basics branches and tags local and remote repos the object store advanced operations end cherry-pick (1/3) A cherry-pick is not very commonly done – in well designed workflows it should actually be rare. However, it’s a good way to illustrate an important concept in git. We said before that a commit represents a certain set of files and directories, but since most commits have only one parent, you can think of a commit as representing a set of changes too. 40 / 52
  • 41. introduction basics branches and tags local and remote repos the object store advanced operations end cherry-pick (2/3) Let’s say one of your collaborators (this mythical “Sita” again!) made a whole bunch of changes to his copy of the repo. You don’t like most of these changes, except one specific change which you would like to bring in to your repo. The starting point is this: 41 / 52
  • 42. introduction basics branches and tags local and remote repos the object store advanced operations end cherry picking (3/3) git cherry-pick sitas-repo/master~1 This results in the following commit graph. 42 / 52
  • 43. introduction basics branches and tags local and remote repos the object store advanced operations end rebasing (1/5) Instead of merging, let’s say you wanted to rebase your commits on top of Sita’s commits. First of all, what is rebasing? It’s basically transplanting a series of changes from one point in the graph to another point. So if you guessed that a rebase was (in principle) a series of cherry-picks, you’d be pretty close, at least from a concept point. 43 / 52
  • 44. introduction basics branches and tags local and remote repos the object store advanced operations end rebasing (2/5) So let’s use a similar example as in the merge example before, but instead of sitas-repo, the new commits are in origin (which is the “main” server for this project). You had your own commits, and you did a git fetch origin which brought in the latest commits from “origin”, so it looks like: 44 / 52
  • 45. introduction basics branches and tags local and remote repos the object store advanced operations end rebasing (3/5) Now, instead of merging origin/master into your local master, you want to rebase your commits on top of origin/master. That is, you want to pretend your local changes were made after commit 13 on the origin. So you run git rebase origin/master and this is the result: 45 / 52
  • 46. introduction basics branches and tags local and remote repos the object store advanced operations end rebasing (4/5) Unlike cherry-pick, a rebase is quite often done in real life. Rebase also has some other forms. This form is one, but the most common is when a developer wants to re-arrange his own local commits in a more logical sequence before publishing/pushing them. 46 / 52
  • 47. introduction basics branches and tags local and remote repos the object store advanced operations end rebasing (5/5) I often do the eqvt of changing this: where “22delta” is a minor fixup to “22”, into using git rebase -i 47 / 52
  • 48. introduction basics branches and tags local and remote repos the object store advanced operations end non fast-forward merge (1/2) Here’s the starting point : 48 / 52
  • 49. introduction basics branches and tags local and remote repos the object store advanced operations end non fast-forward merge (2/2) git merge --no-ff feature_X 49 / 52
  • 50. introduction basics branches and tags local and remote repos the object store advanced operations end “A successful Git branching model” 50 / 52
  • 51. introduction basics branches and tags local and remote repos the object store advanced operations end Resources git concepts simplified A Visual Git Reference git cheat sheet An introduction to git-svn for Subversion/SVK users and deserters pro git mémento git à 100% A successful Git branching model 51 / 52
  • 52. introduction basics branches and tags local and remote repos the object store advanced operations end copyrights + license ©Copyright Sitaram Chamarty, sitaramc@gmail.com (for parts originally in git concepts simplified) ©Copyright Mark Lodato, lodatom@gmail.com (for parts from A Visual Git Reference) ©Copyright Vincent Driessen (for parts from A successful Git branching model) ©Copyright 2012 Olivier Berger + Institut Mines Télécom This documentation is provided under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Made with org-mode (under emacs, to generate beamer slides with inline dot graphs) 52 / 52