SlideShare a Scribd company logo
Git - An Introduction
    Alex R. M. Turner
     August 24th, 2011
Why DVCS, and why Git?
Why DVCS, and why Git?

     It makes development faster
        … plus it was written by Linus Torvalds, so it must be awesome!
What makes DVCS so great?
DVCS makes life better!



•   Less time fighting your tool,

         More time writing code!


•   Less time figuring out what happened,

         More time solving the problem.
SVN, The Straight Jacket
           SVN is a single source system. Everybody speaks to the central repository, and every
           check-in and check-out is put and made from there.
           To check code in, you must have a network connection, and a route to the server.

           A check-in cannot occur if the branch has diverged, a merge is required, though it's
           called an update, and SVN doesn't keep any knowledge that it was actually a merge!




                                                   SVN
                                                  Server




                               Klag                Marie                 Joe




                     •   Check-outs are slow
                     •   Commits are infrequent
                     •   Branching causes a checkout to pull all the files over again


Infrequent commits lead to gargantuan merges, which suck in any system, and SVN's merge tools aren't great.
Expensive branch check-out makes developers reluctant to branch
DVS - The general proposition


              Each repository in a DVCS (Distributed Version Control System) has a complete revision history
              for any branch that is present, including remotely tracked branches (mostly).



For Git, having a single server that everybody synchronizes
with, is just one of a few potential configurations. This is the
model that is used most frequently in a corporate environment.                          Git
                                                                                      Remote
This gives a single place that can be managed including things
like back-ups and high-availability.


This model allows for a few things that make life
for developers significantly better:

  •   Frequent commits
  •   Horizontal change-set sharing
  •   Commits without internet connectivity
  •   Branches retain all comments and context
      especially around merges

                                                                  Klag                                     Marie
Git - Emerging as the leading DVCS

           •    Git designed and initially built by Linus Torvalds
           •    Designed to manage the codebase for the Linux kernel


                             Why is it called git?

  •   Linus jokes that he names programs after himself.
  •   Git is a British English term that roughly means a person who is somewhat
      arrogant, obnoxious and slightly sadistic.
  •   Linus hates wasting time having to merge many many changes every day, so
      he made git as fast as possible, and he knows the kernel, so it is very fast.

      Very very fast, all network transfers are heavily compressed, large merges
      happen with sub-second response time on UNIXish OSes generating fewer
      conflicts than other systems

Extremely powerful functionality:
 •    Cheap branching and merging
 •    Guarenteed data integrity
 •    Selective commits
 •    Sophisticating merging algorithms
 •    Stashing
 •    Multiple merge strategies that can merge multiple branches
 •    Fast diffs
 •    Patchset generation
 •    Compact Syntax
 •    Cherry Picking
 •    Rebasing
 •    Branch Filtering
 •    SVN Porting tools!
How do I use Git?
Get the code from the remote repository

                                  git clone http://github.com/foo

                                  What happened?

                                                                                                 Remote Server

Local System

                                     Checkout                                    Clone
      Working Copy                                           Local                                            Remote


    On a clone, git assumes                                                                                    Remote git packs
    you also want local files,
    so does a checkout.             Remote's HEAD gets copied to local,
                                    which is a branch labelled "master".




                  HEAD is a descriptor that references the last element of a branch in a repository that is
                  the current branch.
Sending changes back to the repository


                                      Add          Commit               Push


                                                                                 Remote Server

Local System


                               Commit                                     Push
   Working Copy
            git clone http://github.com/foo        Local                                Remote


   Add files:      What justCommit:
                           happened?            Push local to remote:                     Remote git packs
   git add                git commit -m       git push 
   file1.txt src/main      "Added some files"   origin master
Filling in a Few Gaps


                   The Index is git's log of what's going on. It contains a list of files and their
                   state relative to HEAD.




Local System


                                         Index
                                                            Commit
                      Add
                                                                                                     Remote Server

                             Checkout                                                   Push

    Working Copy                                        Local                                                Remote
                              Commit                                          Fetch
What is a Branch?


                            master            8a63a7

                              test             76f43a


         master   test
8a63a7                   76f43a                   8a63a7                       76f43a




                         26df25c                  463e5c                       26df25c
463e5c



6c75877                                                  6c75877




26a562c                                                  26a562c



                               A revision keeps track of its predecessor(s).
                               This is how a branch is defined, a successive set of revisions that have a
                               common ancestor. The lineage is given a label, and that is a reference to
                               the branch. It isn't a name per se, it's a reference or pointer. You can
                               change the label, or move it, but the underlying branch lineage doesn't
                               change.
Pushing Changes - A Fast Forward
            When there are only a single person's changes being sent upstream, it's pretty easy.
            This operation is described as a fast-forward


             Local System                                          Remote Server


                                                 Push
                      Local                                                Remote




                       8a63a7                                                 8a63a7




                       463e5c                 Fast Forward                    463e5c




                        6c75877                                               6c75877




Common Ancestor        26a562c                                                26a562c
Divergent branches

     When you try to push, and the remote has been updated since you last fetched, it will reject your push



               Local System                                         Remote Server

                                                    Push

                        Local                                               Remote




                                6c75877                                              463e5c




                                26a562c                                              26a562c




The two branches have a common ancestor, but a divergent HEAD. Pushing to a remote branch must be a "fast-
forward". This means that the current revision on the remote, must be an ancestor of your current HEAD. When
this occurs, what transpires is described as a fast-forward.
Retrieving and Merging


         Local System                                      Remote Server


                                            Fetch
                  Local                                          Remote




                          6c75877                                          463e5c




                          26a562c                                          26a562c




                             Show the difference:
                             git diff --stat origin/master
Retrieve the changes:                                             Perform the Merge:
git fetch                                                         git merge origin/master
                             Show the difference detail:
                             git diff origin/master
Merging - What happens

                        26a562c          6c75877



                                          master
                                                           Merge
                        26a562c          463e5c
                                                                            8a63a7


                                      origin/master




When a merge occurs, git uses one of the merge strategies to resolve differences:

  •   resolve                   3-way merge that is good at detecting crisscross merges, doesn't do renames
  •   recursive
      •   ours                  conflicts are resolved with our version
      •   theirs                conflicts are resolved with their version
      •   patience              takes a bit more time, good for merging highly divergent branches
      •   renormalize           pre-flight normalization for things like line-endings
      •   no-renormalize        disable the previous
      •   subtree[=<path>]      merge knowing that one branch is in a subdirectory of the other

  •   octopus                   merge more than two branches
  •   ours                      merge taking our history exclusively
  •   subtree                   less granular subdirectory merge
Merge Outcome - What does it look like?



origin/master          master
                                 The revision 8a63a7 has two predecessors

                                  •   6c75877
                                  •   463e5c
  8a63a7




  463e5c              6c75877




 26a562c
Conflict Conflagration!


   When there are intersecting changes that can't be resolved by
   the merge tool
   Manual intervention is required!



6c75877



master

                                  Conflict!
                        Merge                  Index               Working Copy



origin/
master


463e5c
The Index keeps track of the status of things

               Index                  Query the index to find out if there's more left to merge
                                      git status

                                      Add files to indicate they are merged
                                      git add poem.txt
        Working Copy
                                      Commit files once they've all been merge and push

        Fix poem.txt                  git commit -m "Merged, dropped Klag's changes"

Index   Still conflicted?

        Fix index.html

Index   Still conflicted?
        Nope

                           Add
        Working Copy              Index


                                     Commit




                                 master                              Remote
                                                    Push
I totally fubared the Merge!


You can get back to pre-merge state with a reset:

get reset --hard HEAD




                     6c75877 - HEAD
        26a562c
                                                          reset

                          master
                                                    working         working
                                           Index     files            files
        26a562c          463e5c
                                                    conflicted     local changes


                       origin/master




This also works for reverting changes
Ammending a Commit

                 •    I wrote a message, but it was crap
                 •    I forgot to add some files



     master
                                                      amend




                26a562c             8a63a7           463e5c




Amending a commit after pushing will result in a conflict!


You created a new revision, with a new hash, and the remote has your old
commit as HEAD which isn't an ancestor for your local master so a push is no
longer a fast-foward


All is not lost though, you can fetch and merge like normal
Good Git Usage




Use .gitignore
 • It contains a list of patterns for files to ignore


Always add explicitly, never use git commit -a, or git add.


Always check your status with git status before you commit
  • If you commit hastily and push too quick, you'll end up
     with files that shouldn't be there!
The End!

Questions?

More Related Content

What's hot

Novedades Denali Integration Services
Novedades Denali Integration ServicesNovedades Denali Integration Services
Novedades Denali Integration Services
SolidQ
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrsTim Mahy
 
Ian Pratt Nsdi Keynote Apr2008
Ian Pratt Nsdi Keynote Apr2008Ian Pratt Nsdi Keynote Apr2008
Ian Pratt Nsdi Keynote Apr2008
The Linux Foundation
 
Kscope 2013 delphix
Kscope 2013 delphixKscope 2013 delphix
Kscope 2013 delphix
Kyle Hailey
 
Delphix for DBAs by Jonathan Lewis
Delphix for DBAs by Jonathan LewisDelphix for DBAs by Jonathan Lewis
Delphix for DBAs by Jonathan Lewis
Kyle Hailey
 
Transforming IT Infrastructure
Transforming IT InfrastructureTransforming IT Infrastructure
Transforming IT Infrastructure
tim_evdbt
 
XS Oracle 2009 PVOps
XS Oracle 2009 PVOpsXS Oracle 2009 PVOps
XS Oracle 2009 PVOps
The Linux Foundation
 
Finding Virtual Coins in the Couch
Finding Virtual Coins in the CouchFinding Virtual Coins in the Couch
Finding Virtual Coins in the Couch
Novell
 
Delphix Platform Overview
Delphix Platform OverviewDelphix Platform Overview
Delphix Platform Overview
Franco_Dagosto
 
Nat load balance_5.0e_feature_module
Nat load balance_5.0e_feature_moduleNat load balance_5.0e_feature_module
Nat load balance_5.0e_feature_moduleLuis Nagasako
 
BSDcon Asia 2015: Xen on FreeBSD
BSDcon Asia 2015: Xen on FreeBSDBSDcon Asia 2015: Xen on FreeBSD
BSDcon Asia 2015: Xen on FreeBSD
The Linux Foundation
 
JUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
JUDCon London 2011 - Elastic SOA on the Cloud, Steve MillidgeJUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
JUDCon London 2011 - Elastic SOA on the Cloud, Steve MillidgeC2B2 Consulting
 
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
The Linux Foundation
 
Using Puppet - Real World Configuration Management
Using Puppet - Real World Configuration ManagementUsing Puppet - Real World Configuration Management
Using Puppet - Real World Configuration Management
James Turnbull
 
XPDDS18: Xen Testing at Intel - Xudong Hao, Intel
XPDDS18: Xen Testing at Intel - Xudong Hao, IntelXPDDS18: Xen Testing at Intel - Xudong Hao, Intel
XPDDS18: Xen Testing at Intel - Xudong Hao, Intel
The Linux Foundation
 
Securing Your Cloud With the Xen Hypervisor by Russell Pavlicek
Securing Your Cloud With the Xen Hypervisor by Russell PavlicekSecuring Your Cloud With the Xen Hypervisor by Russell Pavlicek
Securing Your Cloud With the Xen Hypervisor by Russell Pavlicek
buildacloud
 
Branch repeater technical training presentation 26 oct-12
Branch repeater technical training presentation 26 oct-12Branch repeater technical training presentation 26 oct-12
Branch repeater technical training presentation 26 oct-12
Nuno Alves
 
Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)
National Cheng Kung University
 
DB2 for z/OS Solutions
DB2 for z/OS SolutionsDB2 for z/OS Solutions
DB2 for z/OS Solutions
softbasemarketing
 

What's hot (20)

Novedades Denali Integration Services
Novedades Denali Integration ServicesNovedades Denali Integration Services
Novedades Denali Integration Services
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrs
 
Ian Pratt Nsdi Keynote Apr2008
Ian Pratt Nsdi Keynote Apr2008Ian Pratt Nsdi Keynote Apr2008
Ian Pratt Nsdi Keynote Apr2008
 
Kscope 2013 delphix
Kscope 2013 delphixKscope 2013 delphix
Kscope 2013 delphix
 
Delphix for DBAs by Jonathan Lewis
Delphix for DBAs by Jonathan LewisDelphix for DBAs by Jonathan Lewis
Delphix for DBAs by Jonathan Lewis
 
What is Delphix
What is DelphixWhat is Delphix
What is Delphix
 
Transforming IT Infrastructure
Transforming IT InfrastructureTransforming IT Infrastructure
Transforming IT Infrastructure
 
XS Oracle 2009 PVOps
XS Oracle 2009 PVOpsXS Oracle 2009 PVOps
XS Oracle 2009 PVOps
 
Finding Virtual Coins in the Couch
Finding Virtual Coins in the CouchFinding Virtual Coins in the Couch
Finding Virtual Coins in the Couch
 
Delphix Platform Overview
Delphix Platform OverviewDelphix Platform Overview
Delphix Platform Overview
 
Nat load balance_5.0e_feature_module
Nat load balance_5.0e_feature_moduleNat load balance_5.0e_feature_module
Nat load balance_5.0e_feature_module
 
BSDcon Asia 2015: Xen on FreeBSD
BSDcon Asia 2015: Xen on FreeBSDBSDcon Asia 2015: Xen on FreeBSD
BSDcon Asia 2015: Xen on FreeBSD
 
JUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
JUDCon London 2011 - Elastic SOA on the Cloud, Steve MillidgeJUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
JUDCon London 2011 - Elastic SOA on the Cloud, Steve Millidge
 
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
XPDDS18: Real Time in XEN on ARM - Andrii Anisov, EPAM Systems Inc.
 
Using Puppet - Real World Configuration Management
Using Puppet - Real World Configuration ManagementUsing Puppet - Real World Configuration Management
Using Puppet - Real World Configuration Management
 
XPDDS18: Xen Testing at Intel - Xudong Hao, Intel
XPDDS18: Xen Testing at Intel - Xudong Hao, IntelXPDDS18: Xen Testing at Intel - Xudong Hao, Intel
XPDDS18: Xen Testing at Intel - Xudong Hao, Intel
 
Securing Your Cloud With the Xen Hypervisor by Russell Pavlicek
Securing Your Cloud With the Xen Hypervisor by Russell PavlicekSecuring Your Cloud With the Xen Hypervisor by Russell Pavlicek
Securing Your Cloud With the Xen Hypervisor by Russell Pavlicek
 
Branch repeater technical training presentation 26 oct-12
Branch repeater technical training presentation 26 oct-12Branch repeater technical training presentation 26 oct-12
Branch repeater technical training presentation 26 oct-12
 
Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)Implement Checkpointing for Android (ELCE2012)
Implement Checkpointing for Android (ELCE2012)
 
DB2 for z/OS Solutions
DB2 for z/OS SolutionsDB2 for z/OS Solutions
DB2 for z/OS Solutions
 

Similar to Git 101

Git
GitGit
Making the switch to DVCS
Making the switch to DVCSMaking the switch to DVCS
Making the switch to DVCS
Sven Peters
 
Embracing Distributed Version Control
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version ControlNowell Strite
 
Git
GitGit
Mercurial - Distributed Version Controlling
Mercurial - Distributed Version Controlling Mercurial - Distributed Version Controlling
Mercurial - Distributed Version Controlling
Jayantha Sirisena
 
Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Chen-Han Hsiao
 
Session git
Session gitSession git
Session git
Roni Saha
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?
Paradigma Digital
 
Svn vs mercurial vs github
Svn  vs  mercurial vs  githubSvn  vs  mercurial vs  github
Svn vs mercurial vs githubVinoth Kannan
 
Source control - what you need to know
Source control - what you need to knowSource control - what you need to know
Source control - what you need to know
daveymni
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
Aidan Casey
 
Git more done
Git more doneGit more done
Git more done
Kwen Peterson
 
Deployment with capistrano
Deployment with capistranoDeployment with capistrano
Deployment with capistrano
sagar junnarkar
 
Version Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part IVersion Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part I
Sergey Aganezov
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Callon Campbell
 
Living with Files More Happily
Living with Files More HappilyLiving with Files More Happily
Living with Files More Happily
Yusuke Endo
 
Make It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version ControlMake It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version Control
indiver
 
An introduction to Git and GitFlow
An introduction to Git and GitFlowAn introduction to Git and GitFlow
An introduction to Git and GitFlow
Mark Everard
 

Similar to Git 101 (20)

Git
GitGit
Git
 
Making the switch to DVCS
Making the switch to DVCSMaking the switch to DVCS
Making the switch to DVCS
 
Embracing Distributed Version Control
Embracing Distributed Version ControlEmbracing Distributed Version Control
Embracing Distributed Version Control
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git
GitGit
Git
 
Mercurial - Distributed Version Controlling
Mercurial - Distributed Version Controlling Mercurial - Distributed Version Controlling
Mercurial - Distributed Version Controlling
 
Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15Git basic stanley hsiao 2010_12_15
Git basic stanley hsiao 2010_12_15
 
Session git
Session gitSession git
Session git
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?
 
Svn vs mercurial vs github
Svn  vs  mercurial vs  githubSvn  vs  mercurial vs  github
Svn vs mercurial vs github
 
Source control - what you need to know
Source control - what you need to knowSource control - what you need to know
Source control - what you need to know
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Git more done
Git more doneGit more done
Git more done
 
Deployment with capistrano
Deployment with capistranoDeployment with capistrano
Deployment with capistrano
 
Version Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part IVersion Control Systems -- Git -- Part I
Version Control Systems -- Git -- Part I
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Living with Files More Happily
Living with Files More HappilyLiving with Files More Happily
Living with Files More Happily
 
Make It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version ControlMake It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version Control
 
An introduction to Git and GitFlow
An introduction to Git and GitFlowAn introduction to Git and GitFlow
An introduction to Git and GitFlow
 
Git
GitGit
Git
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Git 101

  • 1. Git - An Introduction Alex R. M. Turner August 24th, 2011
  • 2. Why DVCS, and why Git?
  • 3. Why DVCS, and why Git? It makes development faster … plus it was written by Linus Torvalds, so it must be awesome!
  • 4. What makes DVCS so great?
  • 5. DVCS makes life better! • Less time fighting your tool, More time writing code! • Less time figuring out what happened, More time solving the problem.
  • 6. SVN, The Straight Jacket SVN is a single source system. Everybody speaks to the central repository, and every check-in and check-out is put and made from there. To check code in, you must have a network connection, and a route to the server. A check-in cannot occur if the branch has diverged, a merge is required, though it's called an update, and SVN doesn't keep any knowledge that it was actually a merge! SVN Server Klag Marie Joe • Check-outs are slow • Commits are infrequent • Branching causes a checkout to pull all the files over again Infrequent commits lead to gargantuan merges, which suck in any system, and SVN's merge tools aren't great. Expensive branch check-out makes developers reluctant to branch
  • 7. DVS - The general proposition Each repository in a DVCS (Distributed Version Control System) has a complete revision history for any branch that is present, including remotely tracked branches (mostly). For Git, having a single server that everybody synchronizes with, is just one of a few potential configurations. This is the model that is used most frequently in a corporate environment. Git Remote This gives a single place that can be managed including things like back-ups and high-availability. This model allows for a few things that make life for developers significantly better: • Frequent commits • Horizontal change-set sharing • Commits without internet connectivity • Branches retain all comments and context especially around merges Klag Marie
  • 8. Git - Emerging as the leading DVCS • Git designed and initially built by Linus Torvalds • Designed to manage the codebase for the Linux kernel Why is it called git? • Linus jokes that he names programs after himself. • Git is a British English term that roughly means a person who is somewhat arrogant, obnoxious and slightly sadistic. • Linus hates wasting time having to merge many many changes every day, so he made git as fast as possible, and he knows the kernel, so it is very fast. Very very fast, all network transfers are heavily compressed, large merges happen with sub-second response time on UNIXish OSes generating fewer conflicts than other systems Extremely powerful functionality: • Cheap branching and merging • Guarenteed data integrity • Selective commits • Sophisticating merging algorithms • Stashing • Multiple merge strategies that can merge multiple branches • Fast diffs • Patchset generation • Compact Syntax • Cherry Picking • Rebasing • Branch Filtering • SVN Porting tools!
  • 9. How do I use Git?
  • 10. Get the code from the remote repository git clone http://github.com/foo What happened? Remote Server Local System Checkout Clone Working Copy Local Remote On a clone, git assumes Remote git packs you also want local files, so does a checkout. Remote's HEAD gets copied to local, which is a branch labelled "master". HEAD is a descriptor that references the last element of a branch in a repository that is the current branch.
  • 11. Sending changes back to the repository Add Commit Push Remote Server Local System Commit Push Working Copy git clone http://github.com/foo Local Remote Add files: What justCommit: happened? Push local to remote: Remote git packs git add git commit -m git push file1.txt src/main "Added some files" origin master
  • 12. Filling in a Few Gaps The Index is git's log of what's going on. It contains a list of files and their state relative to HEAD. Local System Index Commit Add Remote Server Checkout Push Working Copy Local Remote Commit Fetch
  • 13. What is a Branch? master 8a63a7 test 76f43a master test 8a63a7 76f43a 8a63a7 76f43a 26df25c 463e5c 26df25c 463e5c 6c75877 6c75877 26a562c 26a562c A revision keeps track of its predecessor(s). This is how a branch is defined, a successive set of revisions that have a common ancestor. The lineage is given a label, and that is a reference to the branch. It isn't a name per se, it's a reference or pointer. You can change the label, or move it, but the underlying branch lineage doesn't change.
  • 14. Pushing Changes - A Fast Forward When there are only a single person's changes being sent upstream, it's pretty easy. This operation is described as a fast-forward Local System Remote Server Push Local Remote 8a63a7 8a63a7 463e5c Fast Forward 463e5c 6c75877 6c75877 Common Ancestor 26a562c 26a562c
  • 15. Divergent branches When you try to push, and the remote has been updated since you last fetched, it will reject your push Local System Remote Server Push Local Remote 6c75877 463e5c 26a562c 26a562c The two branches have a common ancestor, but a divergent HEAD. Pushing to a remote branch must be a "fast- forward". This means that the current revision on the remote, must be an ancestor of your current HEAD. When this occurs, what transpires is described as a fast-forward.
  • 16. Retrieving and Merging Local System Remote Server Fetch Local Remote 6c75877 463e5c 26a562c 26a562c Show the difference: git diff --stat origin/master Retrieve the changes: Perform the Merge: git fetch git merge origin/master Show the difference detail: git diff origin/master
  • 17. Merging - What happens 26a562c 6c75877 master Merge 26a562c 463e5c 8a63a7 origin/master When a merge occurs, git uses one of the merge strategies to resolve differences: • resolve 3-way merge that is good at detecting crisscross merges, doesn't do renames • recursive • ours conflicts are resolved with our version • theirs conflicts are resolved with their version • patience takes a bit more time, good for merging highly divergent branches • renormalize pre-flight normalization for things like line-endings • no-renormalize disable the previous • subtree[=<path>] merge knowing that one branch is in a subdirectory of the other • octopus merge more than two branches • ours merge taking our history exclusively • subtree less granular subdirectory merge
  • 18. Merge Outcome - What does it look like? origin/master master The revision 8a63a7 has two predecessors • 6c75877 • 463e5c 8a63a7 463e5c 6c75877 26a562c
  • 19. Conflict Conflagration! When there are intersecting changes that can't be resolved by the merge tool Manual intervention is required! 6c75877 master Conflict! Merge Index Working Copy origin/ master 463e5c
  • 20. The Index keeps track of the status of things Index Query the index to find out if there's more left to merge git status Add files to indicate they are merged git add poem.txt Working Copy Commit files once they've all been merge and push Fix poem.txt git commit -m "Merged, dropped Klag's changes" Index Still conflicted? Fix index.html Index Still conflicted? Nope Add Working Copy Index Commit master Remote Push
  • 21. I totally fubared the Merge! You can get back to pre-merge state with a reset: get reset --hard HEAD 6c75877 - HEAD 26a562c reset master working working Index files files 26a562c 463e5c conflicted local changes origin/master This also works for reverting changes
  • 22. Ammending a Commit • I wrote a message, but it was crap • I forgot to add some files master amend 26a562c 8a63a7 463e5c Amending a commit after pushing will result in a conflict! You created a new revision, with a new hash, and the remote has your old commit as HEAD which isn't an ancestor for your local master so a push is no longer a fast-foward All is not lost though, you can fetch and merge like normal
  • 23. Good Git Usage Use .gitignore • It contains a list of patterns for files to ignore Always add explicitly, never use git commit -a, or git add. Always check your status with git status before you commit • If you commit hastily and push too quick, you'll end up with files that shouldn't be there!