SlideShare a Scribd company logo
1 of 24
Download to read offline
Git: a brief
                                  introduction
                     Randal L. Schwartz, merlyn@stonehenge.com
                             Version 5.0.2 on 28 Jul 2012

                        This document is copyright 2011, 2012 by Randal L. Schwartz, Stonehenge Consulting Services, Inc.
                  This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
                                                http://creativecommons.org/licenses/by-nc-sa/3.0/




Saturday, August 4, 12
Overview

                     •   Key concepts of git
                     •   Using git by yourself
                     •   Using git with others




Saturday, August 4, 12
Key concepts
                     •   Manages trees, not files
                     •   Stores entire history for a commit
                     •   Serverless (mostly)
                     •   Source-code manager
                       •   No meta-data
                       •   Handles binaries badly
                     •   Optimized for branch/merge
                       •   If not branching or merging, bad fit



Saturday, August 4, 12
The moving parts
                     •   Stored in “.git”:
                         • Object repository
                           • files (“blob”), directories, commits
                         • Operational files (config, etc.)
                     •   Working directory
                     •   Low-level CLI (“plumbing”)
                     •   High-level CLI (“porcelain”)
                     •   Various GUIs
                     •   Various web UIs



Saturday, August 4, 12
Commits
                     •   Unit of work
                     •   Usually has a parent
                         • Two or more on a merge
                         • Zero on a “root” commit
                     •   Metadata (committer, message, timestamps)
                     •   Tree of files at time of commit




Saturday, August 4, 12
Trees
                     • SHA1 of each file in a directory
                     • SHA1 of each directory
                       • ... recursively
                     • These are kept efficiently in the object store
                     • Identical files map to same SHA1, stored once
                       • And so do identical trees!
                     • No penalty to “move” a subdirectory or file

Saturday, August 4, 12
Making commits
                     • Changes made to work dir
                     • Added to index with “git add”
                     • Committed with “git commit”
                     • Commit updates HEAD
                       • Prior value of HEAD is the parent
                     • HEAD almost always points at a branch name
                       • Thus, branch name is also moved forward
                     • Series of commits loosely also called “branch”
                     • Commit also gets a SHA1

Saturday, August 4, 12
The SHA1 is king
                     •   SHA1 of commit defines:
                         • Metadata of commit
                         • Tree of files
                         • Parentage
                     •   Parentage defines previous commits
                     •   Thus, SHA1 uniquely defines complete history
                     •   Useful when working with others




Saturday, August 4, 12
Naming commits
                     •   SHA1 (can often be abbreviated)
                     •   HEAD, branch-name, tag
                     •   Optionally followed by @{historical}
                     •   “historical” can be:
                         • yesterday, 2011-11-22, etc (date ref)
                         • 1, 2, 3, etc (prior version of this ref)
                         • “upstream” (upstream version of local)
                     •   Optionally followed by ~n for “n’th ancestor”



Saturday, August 4, 12
Branches
                     • Initial branch is “master” (name not special)
                     • Fork the current branch:
                       git checkout -b topic1
                     • topic1 is set to same SHA1 as previous branch
                     • HEAD now points at topic1
                       • New commits now apply to topic1
                     • Switch back with “git checkout master”

Saturday, August 4, 12
Multiple branches
                     •   Start a second topic based on original master:
                         git checkout -b topic2 master
                     •   Work, work, commit, commit
                     •   Switch back and forth at will:
                         git checkout topic1
                     •   Topics record independent deltas to master
                         •  A B C (master) D E F (topic1)
                         •  A B C (master) G H I (topic2)



Saturday, August 4, 12
Combining the work
                     •   Merge the work back in to master:
                         git checkout master
                         git merge topic1
                         git branch -d topic1
                     •   This was a fast-forward merge:
                         A B C D E F (new “master”)
                         A B C G H I (topic2)




Saturday, August 4, 12
Really merging
                     •   Now to bring topic2 back into the mix:
                         git checkout master # already there
                         git merge topic2
                     •   Three-way merge between master, topic2,
                         relative to common ancestor (“C”)
                     •   Might cause conflicts
                     •   New commit will have both F and I as parents
                     •   History is no longer linear
                         •  DEF and GHI will appear as parallel lines



Saturday, August 4, 12
Linear history
                     •   We can “rebase” commits:
                         A B C D E F (master)
                         A B C G H I (topic2)
                         git checkout topic2; git rebase master
                     •   Git replays new commits on top of ancestor:
                         A B C D E F (master) G’ H’ I’ (topic2)
                     •   Might cause conflicts at each replay
                     •   Need to clean up when done:
                         git checkout master; git merge topic2
                         git branch -d topic2


Saturday, August 4, 12
Rebase vs merge
                     • Both can have conflicts
                     • Merge makes a bushy tree
                       • Hard to peel out “linear” history
                     • Rebase makes a linear tree
                       • But gets rid of commits
                     • Rebase is nicer, but you must take care
                       • Shared commits should not be rebased

Saturday, August 4, 12
Using git yourself
                     •   Create the repo at your top-level dir:
                         git init
                         git add -A . # or git add *
                         git commit # invokes a text editor
                     •   You now have a single “.git” dir
                     •   The current working dir snapshotted as root




Saturday, August 4, 12
Work a bit
                     •   Edit some files
                     •   Check the status: git status
                     •   Add all the changes and commit them:
                         git add -A .
                         git commit
                     •   Shortcut if you haven’t added new files:
                         git commit -a
                     •   You’re making commits on the master branch



Saturday, August 4, 12
What’s changed?
                     •   git diff
                       •    Diff between index and working tree
                       •    These are things you should “git add”
                       •    “git commit -a” will also make this list empty
                     •   git diff HEAD
                       •    Difference between HEAD and working tree
                       •    “git commit -a” will make this empty
                     •   git diff --cached
                       •    between HEAD and index
                       •    “git commit” (without -a) makes this empty


Saturday, August 4, 12
Useful commands
                     •   git archive: export a tree as a tar/zip
                     •   git bisect: find the offensive commit
                     •   git cherry-pick: selective merging
                     •   git mv: rename a file/dir
                     •   git rm: ditto for delete
                     •   git revert: add commit to undo previous commit
                     •   git blame: who wrote this?




Saturday, August 4, 12
Read the history
                     • git log
                       • print the changes
                     • git log -p
                       • print the changes, including a diff between
                          revisions
                     • git log --stat
                       • Summarize the changes with a diffstat
                     • git log -- file1 file2 dir3
                       • Show changes only for listed files or subdirs

Saturday, August 4, 12
Using git with others
                     •   Commits can be transmitted by many protocols
                         •  On disk
                         •  HTTP[S]
                         •  git protocol over TCP
                         •  git protocol over SSH
                     •   git over SSH is preferred




Saturday, August 4, 12
Getting commits
                     •   Most likely: git clone over SSH:
                         git clone user@host:/some/path/to/repo.git
                     •   Makes local repo.git dir
                     •   Checks out remote repo’s “HEAD” as master
                     •   Adds remote repo as “origin”
                         •  Nothing special about that name




Saturday, August 4, 12
Working with upstream
                     •   Work on local master:
                         edit edit; git commit -a
                     •   Refresh from upstream
                         •  By merge: git pull origin master
                         •  By rebase: git pull --rebase origin master
                     •   Push to upstream:
                         git push origin master
                     •   Check what’s different before pull:
                         git fetch origin; git diff master origin/master



Saturday, August 4, 12
For further info
                     •   See “Git (software)” in Wikipedia
                     •   And the git homepage http://git-scm.com/
                     •   Git wiki at https://git.wiki.kernel.org/
                     •   Wonderful Pro Git book: http://progit.org/book/
                     •   Get on the mailing list
                         • Helpful people there
                         • You can submit bugs, patches, ideas
                     •   And the #git IRC channel (on Freenode)
                     •   Now “git” to it!



Saturday, August 4, 12

More Related Content

What's hot

An introduction to git
An introduction to gitAn introduction to git
An introduction to gitolberger
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started PresentationNap Ramirez
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSMAU
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time rebootKentaro Goto
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Mandi Walls
 
Introduction to github using Egit
Introduction to github using EgitIntroduction to github using Egit
Introduction to github using Egitmatz_twt
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucketazwildcat
 
VCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopVCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopAnis Ahmad
 
Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Gibson Fahnestock
 

What's hot (20)

An introduction to git
An introduction to gitAn introduction to git
An introduction to git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git: A Getting Started Presentation
Git: A Getting Started PresentationGit: A Getting Started Presentation
Git: A Getting Started Presentation
 
Smau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro LocatiSmau Milano 2016 - Fabio Alessandro Locati
Smau Milano 2016 - Fabio Alessandro Locati
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
 
Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1Into The Box 2020 Keynote Day 1
Into The Box 2020 Keynote Day 1
 
Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014Open Source Tools for Leveling Up Operations FOSSET 2014
Open Source Tools for Leveling Up Operations FOSSET 2014
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Talk to git
Talk to gitTalk to git
Talk to git
 
Introduction to github using Egit
Introduction to github using EgitIntroduction to github using Egit
Introduction to github using Egit
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
VCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT WorkshopVCS for Teamwork - GIT Workshop
VCS for Teamwork - GIT Workshop
 
Git 101
Git 101Git 101
Git 101
 
Domino testing presentation
Domino testing presentationDomino testing presentation
Domino testing presentation
 
Node.js what's next (Index 2018)
Node.js what's next (Index 2018)Node.js what's next (Index 2018)
Node.js what's next (Index 2018)
 
Rupher = Ruby + Gopther
Rupher = Ruby + GoptherRupher = Ruby + Gopther
Rupher = Ruby + Gopther
 
Rupher
RupherRupher
Rupher
 

Similar to Intro to git (one hour version)

Similar to Intro to git (one hour version) (19)

Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
Git session-2012-2013
Git session-2012-2013Git session-2012-2013
Git session-2012-2013
 
Git
GitGit
Git
 
Demystifying git
Demystifying git Demystifying git
Demystifying git
 
6 git
6 git6 git
6 git
 
Do you really understand Git?
Do you really understand Git?Do you really understand Git?
Do you really understand Git?
 
Git censored.key
Git censored.keyGit censored.key
Git censored.key
 
Git Real
Git RealGit Real
Git Real
 
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
Embedded Systems: Lecture 11: Introduction to Git & GitHub (Part 2)
 
12-BigDataMapReduce.pptx
12-BigDataMapReduce.pptx12-BigDataMapReduce.pptx
12-BigDataMapReduce.pptx
 
[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop[JVMLS 12] Kotlin / Java Interop
[JVMLS 12] Kotlin / Java Interop
 
Mongodb my
Mongodb myMongodb my
Mongodb my
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
January 2022: Central Iowa Linux Users Group: Git
January 2022: Central Iowa Linux Users Group: GitJanuary 2022: Central Iowa Linux Users Group: Git
January 2022: Central Iowa Linux Users Group: Git
 
What git is
What git isWhat git is
What git is
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
Iwmn architecture
Iwmn architectureIwmn architecture
Iwmn architecture
 

More from Randal Schwartz

Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Randal Schwartz
 
A brief introduction to dart
A brief introduction to dartA brief introduction to dart
A brief introduction to dartRandal Schwartz
 

More from Randal Schwartz (7)

Why Flutter.pdf
Why Flutter.pdfWhy Flutter.pdf
Why Flutter.pdf
 
Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)Native mobile application development with Flutter (Dart)
Native mobile application development with Flutter (Dart)
 
Perl best practices v4
Perl best practices v4Perl best practices v4
Perl best practices v4
 
A brief introduction to dart
A brief introduction to dartA brief introduction to dart
A brief introduction to dart
 
My half life with perl
My half life with perlMy half life with perl
My half life with perl
 
Testing scripts
Testing scriptsTesting scripts
Testing scripts
 
Forget The ORM!
Forget The ORM!Forget The ORM!
Forget The ORM!
 

Recently uploaded

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 

Recently uploaded (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 

Intro to git (one hour version)

  • 1. Git: a brief introduction Randal L. Schwartz, merlyn@stonehenge.com Version 5.0.2 on 28 Jul 2012 This document is copyright 2011, 2012 by Randal L. Schwartz, Stonehenge Consulting Services, Inc. This work is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License http://creativecommons.org/licenses/by-nc-sa/3.0/ Saturday, August 4, 12
  • 2. Overview • Key concepts of git • Using git by yourself • Using git with others Saturday, August 4, 12
  • 3. Key concepts • Manages trees, not files • Stores entire history for a commit • Serverless (mostly) • Source-code manager • No meta-data • Handles binaries badly • Optimized for branch/merge • If not branching or merging, bad fit Saturday, August 4, 12
  • 4. The moving parts • Stored in “.git”: • Object repository • files (“blob”), directories, commits • Operational files (config, etc.) • Working directory • Low-level CLI (“plumbing”) • High-level CLI (“porcelain”) • Various GUIs • Various web UIs Saturday, August 4, 12
  • 5. Commits • Unit of work • Usually has a parent • Two or more on a merge • Zero on a “root” commit • Metadata (committer, message, timestamps) • Tree of files at time of commit Saturday, August 4, 12
  • 6. Trees • SHA1 of each file in a directory • SHA1 of each directory • ... recursively • These are kept efficiently in the object store • Identical files map to same SHA1, stored once • And so do identical trees! • No penalty to “move” a subdirectory or file Saturday, August 4, 12
  • 7. Making commits • Changes made to work dir • Added to index with “git add” • Committed with “git commit” • Commit updates HEAD • Prior value of HEAD is the parent • HEAD almost always points at a branch name • Thus, branch name is also moved forward • Series of commits loosely also called “branch” • Commit also gets a SHA1 Saturday, August 4, 12
  • 8. The SHA1 is king • SHA1 of commit defines: • Metadata of commit • Tree of files • Parentage • Parentage defines previous commits • Thus, SHA1 uniquely defines complete history • Useful when working with others Saturday, August 4, 12
  • 9. Naming commits • SHA1 (can often be abbreviated) • HEAD, branch-name, tag • Optionally followed by @{historical} • “historical” can be: • yesterday, 2011-11-22, etc (date ref) • 1, 2, 3, etc (prior version of this ref) • “upstream” (upstream version of local) • Optionally followed by ~n for “n’th ancestor” Saturday, August 4, 12
  • 10. Branches • Initial branch is “master” (name not special) • Fork the current branch: git checkout -b topic1 • topic1 is set to same SHA1 as previous branch • HEAD now points at topic1 • New commits now apply to topic1 • Switch back with “git checkout master” Saturday, August 4, 12
  • 11. Multiple branches • Start a second topic based on original master: git checkout -b topic2 master • Work, work, commit, commit • Switch back and forth at will: git checkout topic1 • Topics record independent deltas to master • A B C (master) D E F (topic1) • A B C (master) G H I (topic2) Saturday, August 4, 12
  • 12. Combining the work • Merge the work back in to master: git checkout master git merge topic1 git branch -d topic1 • This was a fast-forward merge: A B C D E F (new “master”) A B C G H I (topic2) Saturday, August 4, 12
  • 13. Really merging • Now to bring topic2 back into the mix: git checkout master # already there git merge topic2 • Three-way merge between master, topic2, relative to common ancestor (“C”) • Might cause conflicts • New commit will have both F and I as parents • History is no longer linear • DEF and GHI will appear as parallel lines Saturday, August 4, 12
  • 14. Linear history • We can “rebase” commits: A B C D E F (master) A B C G H I (topic2) git checkout topic2; git rebase master • Git replays new commits on top of ancestor: A B C D E F (master) G’ H’ I’ (topic2) • Might cause conflicts at each replay • Need to clean up when done: git checkout master; git merge topic2 git branch -d topic2 Saturday, August 4, 12
  • 15. Rebase vs merge • Both can have conflicts • Merge makes a bushy tree • Hard to peel out “linear” history • Rebase makes a linear tree • But gets rid of commits • Rebase is nicer, but you must take care • Shared commits should not be rebased Saturday, August 4, 12
  • 16. Using git yourself • Create the repo at your top-level dir: git init git add -A . # or git add * git commit # invokes a text editor • You now have a single “.git” dir • The current working dir snapshotted as root Saturday, August 4, 12
  • 17. Work a bit • Edit some files • Check the status: git status • Add all the changes and commit them: git add -A . git commit • Shortcut if you haven’t added new files: git commit -a • You’re making commits on the master branch Saturday, August 4, 12
  • 18. What’s changed? • git diff • Diff between index and working tree • These are things you should “git add” • “git commit -a” will also make this list empty • git diff HEAD • Difference between HEAD and working tree • “git commit -a” will make this empty • git diff --cached • between HEAD and index • “git commit” (without -a) makes this empty Saturday, August 4, 12
  • 19. Useful commands • git archive: export a tree as a tar/zip • git bisect: find the offensive commit • git cherry-pick: selective merging • git mv: rename a file/dir • git rm: ditto for delete • git revert: add commit to undo previous commit • git blame: who wrote this? Saturday, August 4, 12
  • 20. Read the history • git log • print the changes • git log -p • print the changes, including a diff between revisions • git log --stat • Summarize the changes with a diffstat • git log -- file1 file2 dir3 • Show changes only for listed files or subdirs Saturday, August 4, 12
  • 21. Using git with others • Commits can be transmitted by many protocols • On disk • HTTP[S] • git protocol over TCP • git protocol over SSH • git over SSH is preferred Saturday, August 4, 12
  • 22. Getting commits • Most likely: git clone over SSH: git clone user@host:/some/path/to/repo.git • Makes local repo.git dir • Checks out remote repo’s “HEAD” as master • Adds remote repo as “origin” • Nothing special about that name Saturday, August 4, 12
  • 23. Working with upstream • Work on local master: edit edit; git commit -a • Refresh from upstream • By merge: git pull origin master • By rebase: git pull --rebase origin master • Push to upstream: git push origin master • Check what’s different before pull: git fetch origin; git diff master origin/master Saturday, August 4, 12
  • 24. For further info • See “Git (software)” in Wikipedia • And the git homepage http://git-scm.com/ • Git wiki at https://git.wiki.kernel.org/ • Wonderful Pro Git book: http://progit.org/book/ • Get on the mailing list • Helpful people there • You can submit bugs, patches, ideas • And the #git IRC channel (on Freenode) • Now “git” to it! Saturday, August 4, 12