SlideShare a Scribd company logo
1 of 53
Download to read offline
INSIDE
GIT
GIT INSIDE OUT
MICHAEL NADEL
▸Developer @ Pine River Capital Management
▸New(ish) to .NET
▸3-year Git practitioner
▸Please reach out!
▸michael.nadel@gmail.com
▸@mnadel
GIT INSIDE OUT
GIT IS HARD
▸Linus Torvalds, creator of Git (and Linux)
▸Initial revision of “git”, the information manager from hell
▸I didn’t really expect anyone to use it because it’s so hard
to use.
▸Andrew Morton, lead Linux kernel developer
▸Git is expressly designed to make you feel less intelligent
than you thought you were.
GIT INSIDE OUT
THE CHALLENGE WITH GIT
▸Plenty of rope
▸Paradigm shifts
▸Distributed
▸Content-addressable filesystem
GIT INSIDE OUT
WHY INSIDE OUT?
GIT INSIDE OUT
AGENDA
▸Paradigm shifts
▸Conceptual models
▸Overview of internals
▸Dissect common operations
GIT INSIDE OUT
DISTRIBUTED
▸No central authority (except by convention)
YOUR REPO/CLONE OTHERS’ REPOS
CLONE
FETCH
PUSH
GIT INSIDE OUT
COMMITTING != SHARING
▸Separate concerns
▸Crafting your history
▸Publishing your history
▸Richer workflows
▸Commit, commit, commit, squash, push
▸Reorder, push subset
▸Enforced code reviews
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Version control is an abstraction on top of a primitive
key/value store
▸hash-object
▸cat-file
▸Prove
▸cat-file performs no magic
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Given arbitrary content
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Git primitive: hash-object
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Git returns its key (SHA1 hash of contents)
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Git primitive: cat-file
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Git returns the original content
GIT INSIDE OUT
CONTENT ADDRESSABLE
▸Final proof!
GIT INSIDE OUT
CONTENT ADDRESSABLE FILESYSTEM
▸Instead of text, how about your filesystem?
GIT INSIDE OUT
CONCEPTUAL MODELS
▸Git as a Database
▸Store, retrieve, search your source code & its history
▸Git as a Graph
▸CRUD operations are performed against a graph of
commits
GIT INSIDE OUT
GIT AS A DATABASE
▸CRUD, search operations
▸Data types
▸Commit
▸Tree
▸Blob
Structured text
byte[]
GIT INSIDE OUT
DB TYPE - COMMIT
GIT INSIDE OUT
DB TYPE - COMMIT
GIT INSIDE OUT
DB TYPE - COMMIT
GIT INSIDE OUT
DB TYPE - TREE
GIT INSIDE OUT
DB TYPE - TREE
GIT INSIDE OUT
DB TYPE - TREE
GIT INSIDE OUT
DB TYPE - TREE
GIT INSIDE OUT
DB TYPE - BLOB
GIT INSIDE OUT
CONTENT ADDRESSABLE FILESYSTEM
93b6
ae3e
7bbc63b7
4e3c 3ca5
GIT INSIDE OUT
GIT AS A GRAPH
▸What operations must I perform to get the graph to look the
way I want?
GIT INSIDE OUT
GIT COMMANDMENTS
▸Git is immutable
▸No updates, only appends
▸Git is a directed acyclic graph (DAG)
▸Directed: can only traverse in a single direction
▸Acyclic: no cycles — traversals only visit a node once
▸Every command is an operation on the graph
GIT INSIDE OUT
GIT IS IMMUTABLE
PREVIOUS SNAPSHOTCURRENT SNAPSHOT
▸Branch
▸Commit
▸Fetch
▸Merge
▸Push
▸Rebase
GIT INSIDE OUT
DISSECT COMMON OPERATIONS
GIT INSIDE OUT
REFS, HEADS, BRANCHES
▸Ref is a pointer to a commit
▸Branch is a ref
▸HEAD is a pointer to your current branch
▸Branches have “namespaces”
GIT INSIDE OUT
BRANCH (BEFORE)
▸A branch is a ref
▸A ref is a pointer to a commit
GIT INSIDE OUT
BRANCH (AFTER)
▸A branch is a ref
▸A ref is a pointer to a commit
▸Heads contain your branches
▸Remotes contain remote
branches (eg origin)
▸“Namespaces” are directories
▸Branches are 40-byte files
containing a SHA1 hash of a
commit object
GIT INSIDE OUT
BRANCH IMPLEMENTATION
GIT INSIDE OUT
COMMIT (BEFORE)
▸A commit references its parent
▸HEAD, branch point at commit
GIT INSIDE OUT
COMMIT (AFTER)
▸Add a new node
▸Advance branch
GIT INSIDE OUT
FETCH (BEFORE)
▸Fetch brings remote objects into repo
▸Refs, commits
▸But Git is immutable
▸Graft remote commits into graph
▸Updates refs in remote namespace
GIT INSIDE OUT
FETCH (AFTER)
GIT INSIDE OUT
MERGE (BEFORE)
▸Merge is just a commit object
▸But which refers to two parents
GIT INSIDE OUT
MERGE (AFTER)
▸Creates new commit with two parents
▸Current branch, other branch
▸Advance branch
GIT INSIDE OUT
FAST-FORWARD MERGE (BEFORE)
▸Type of merge
▸Is there a traversal from your branch to the other’s?
GIT INSIDE OUT
FAST-FORWARD MERGE (AFTER)
▸Simplest merge
▸Pointer manipulation only
GIT INSIDE OUT
REBASE (BEFORE)
▸Type of merge
▸Without merge commit objects
GIT INSIDE OUT
REBASE (AFTER)
▸Replay your commits onto the other branch
GIT INSIDE OUT
PUSH
▸Two-step process
▸“Reverse” fetch — push commits, refs
▸Attempt a fast-forward merge
GIT INSIDE OUT
PUSH
▸What will happen if you push?
▸How do you recover?
GIT INSIDE OUT
SAVING YOURSELF - RESET
GIT INSIDE OUT
SAVING YOURSELF - REFLOG
GIT INSIDE OUT
SAVING YOURSELF - INTERACTIVE
REBASE
GIT INSIDE OUT
RECAP - CONCEPTUAL MODELS
▸Duality of Git
▸As a database
▸As an immutable DAG
▸Reasoning through problems
▸Launch SmartGit & observe the result of commands
against the DAG
GIT INSIDE OUT
RECAP - “OH SHIT!” COMMANDS
▸git reflog
▸git reset
▸—soft won’t affect your workspace
▸—hard will make your workspace reflect where your
HEAD moved to (you can lose work)
▸git rebase -i
GIT INSIDE OUT
RESOURCES
▸https://git-scm.com/book/en/v1/Git-Internals
▸https://github.com/pluralsight/git-internals-pdf/releases
▸https://pinboard.in/u:mnadel/t:git/
▸http://www.syntevo.com/smartgit/
▸Free for open source projects
▸Also: https://www.sourcetreeapp.com/
▸michael.nadel@gmail.com

More Related Content

Viewers also liked (7)

Getting Git
Getting GitGetting Git
Getting Git
 
Macmillan english grammar in context advance by machael vince
Macmillan english grammar in context advance by machael vinceMacmillan english grammar in context advance by machael vince
Macmillan english grammar in context advance by machael vince
 
3 Macmillan english_grammar_in_context_advance
3 Macmillan english_grammar_in_context_advance3 Macmillan english_grammar_in_context_advance
3 Macmillan english_grammar_in_context_advance
 
Clarke, simon english grammar in context essential
Clarke, simon   english grammar in context essentialClarke, simon   english grammar in context essential
Clarke, simon english grammar in context essential
 
face2face Elementary student's book 2nd edition
face2face Elementary student's book 2nd editionface2face Elementary student's book 2nd edition
face2face Elementary student's book 2nd edition
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 
English book oxford practice grammar with answers
English book   oxford practice grammar with answersEnglish book   oxford practice grammar with answers
English book oxford practice grammar with answers
 

Similar to Git inside out

git- Most Of The Things About a Trending DVCS
git- Most Of The Things About a Trending DVCSgit- Most Of The Things About a Trending DVCS
git- Most Of The Things About a Trending DVCSIsuru Wimalasundera
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheetsozone777
 
GIT workshop at Selenium Conference 2018
GIT workshop at Selenium Conference 2018GIT workshop at Selenium Conference 2018
GIT workshop at Selenium Conference 2018Pooja Shah
 
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...AmyJune Hineline (she-her)
 
Git lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeGit lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeAkarsh Satija
 
Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Mizan Riqzia
 
Pragmatic Git workflow
Pragmatic Git workflowPragmatic Git workflow
Pragmatic Git workflowTomek Cejner
 
GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807Shota Ito
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitAmit Mathur
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 
Enterprise git
Enterprise gitEnterprise git
Enterprise gitPedro Melo
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Source control management
Source control managementSource control management
Source control managementOwen Winkler
 

Similar to Git inside out (20)

Git
GitGit
Git
 
Git training
Git trainingGit training
Git training
 
git- Most Of The Things About a Trending DVCS
git- Most Of The Things About a Trending DVCSgit- Most Of The Things About a Trending DVCS
git- Most Of The Things About a Trending DVCS
 
Git cheat-sheets
Git cheat-sheetsGit cheat-sheets
Git cheat-sheets
 
Git.odp 0
Git.odp 0Git.odp 0
Git.odp 0
 
GIT workshop at Selenium Conference 2018
GIT workshop at Selenium Conference 2018GIT workshop at Selenium Conference 2018
GIT workshop at Selenium Conference 2018
 
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...
WordFest Live 2022 - Git into the Groove - Moving from Freelance to Collabora...
 
Git lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars themeGit lord | A brief intro about git commands in Star Wars theme
Git lord | A brief intro about git commands in Star Wars theme
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)Nge-GIT (Belajar Git Bareng)
Nge-GIT (Belajar Git Bareng)
 
Pragmatic Git workflow
Pragmatic Git workflowPragmatic Git workflow
Pragmatic Git workflow
 
Github By Nyros Developer
Github By Nyros DeveloperGithub By Nyros Developer
Github By Nyros Developer
 
GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807GitLab_meetup_tokyo_201807
GitLab_meetup_tokyo_201807
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
simple Git
simple Git simple Git
simple Git
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git basics
Git basicsGit basics
Git basics
 
Enterprise git
Enterprise gitEnterprise git
Enterprise git
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Source control management
Source control managementSource control management
Source control management
 

Recently uploaded

Managing Planning and Development of Citie- 26-2-24.docx
Managing Planning and  Development of  Citie-  26-2-24.docxManaging Planning and  Development of  Citie-  26-2-24.docx
Managing Planning and Development of Citie- 26-2-24.docxJIT KUMAR GUPTA
 
Sensitivity Training for 2023 BSKE.pptx
Sensitivity Training for  2023 BSKE.pptxSensitivity Training for  2023 BSKE.pptx
Sensitivity Training for 2023 BSKE.pptxAllidaacLuap
 
2024: The FAR, Federal Acquisition Regulations - Part 16
2024: The FAR, Federal Acquisition Regulations - Part 162024: The FAR, Federal Acquisition Regulations - Part 16
2024: The FAR, Federal Acquisition Regulations - Part 16JSchaus & Associates
 
PPT Item # 2 -- Announcements Powerpoint
PPT Item # 2 -- Announcements PowerpointPPT Item # 2 -- Announcements Powerpoint
PPT Item # 2 -- Announcements Powerpointahcitycouncil
 
World Happiness Report 2024- Full Report
World Happiness Report 2024- Full ReportWorld Happiness Report 2024- Full Report
World Happiness Report 2024- Full ReportEnergy for One World
 
Water and peace go hand-in hand. World Water Day 2024
Water and peace go hand-in hand. World Water Day 2024Water and peace go hand-in hand. World Water Day 2024
Water and peace go hand-in hand. World Water Day 2024Christina Parmionova
 
Living life to the full: How can we make our longer lives healthier, happier ...
Living life to the full: How can we make our longer lives healthier, happier ...Living life to the full: How can we make our longer lives healthier, happier ...
Living life to the full: How can we make our longer lives healthier, happier ...ResolutionFoundation
 
CBO’s Work on Health Care and a Call for New Research
CBO’s Work on Health Care and a Call for New ResearchCBO’s Work on Health Care and a Call for New Research
CBO’s Work on Health Care and a Call for New ResearchCongressional Budget Office
 
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS: relato de expe...
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS:  relato de expe...O Conselho Estadual de Cultura e o Incentivo à Cultura no RS:  relato de expe...
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS: relato de expe...Alvaro Santi
 
War in Ukraine and problematics of the Ukrainian refugees in USA
War in Ukraine and problematics of the Ukrainian refugees in USAWar in Ukraine and problematics of the Ukrainian refugees in USA
War in Ukraine and problematics of the Ukrainian refugees in USAival6
 
Item # 1a - March 18, 2024 Special CCM Minutes
Item # 1a - March 18, 2024 Special CCM MinutesItem # 1a - March 18, 2024 Special CCM Minutes
Item # 1a - March 18, 2024 Special CCM Minutesahcitycouncil
 
2024: The FAR, Federal Acquisition Regulations - Part 17
2024: The FAR, Federal Acquisition Regulations - Part 172024: The FAR, Federal Acquisition Regulations - Part 17
2024: The FAR, Federal Acquisition Regulations - Part 17JSchaus & Associates
 
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...Congressional Budget Office
 
Yes!? We can end TB - World Tuberculosis Day 2024.
Yes!? We can end TB - World Tuberculosis Day 2024.Yes!? We can end TB - World Tuberculosis Day 2024.
Yes!? We can end TB - World Tuberculosis Day 2024.Christina Parmionova
 
Children who live with Grandparents are really lucky
Children who live with Grandparents are really luckyChildren who live with Grandparents are really lucky
Children who live with Grandparents are really luckySERUDS INDIA
 
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptx
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptxDB9_BTR_Webinar_Slidedeck_20230320 (1).pptx
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptxNAP Global Network
 
Water can create peace or spark conflict.
Water can create peace or spark conflict.Water can create peace or spark conflict.
Water can create peace or spark conflict.Christina Parmionova
 
Water for Prosperity and peace - United Nations World Water Development Repo...
Water for Prosperity and peace -  United Nations World Water Development Repo...Water for Prosperity and peace -  United Nations World Water Development Repo...
Water for Prosperity and peace - United Nations World Water Development Repo...Christina Parmionova
 
What Teenagers Have to Say about the Grandparents
What Teenagers Have to Say about the GrandparentsWhat Teenagers Have to Say about the Grandparents
What Teenagers Have to Say about the GrandparentsSERUDS INDIA
 
Hub Design Inspiration Graphics for inspiration
Hub Design Inspiration Graphics for inspirationHub Design Inspiration Graphics for inspiration
Hub Design Inspiration Graphics for inspirationStephen Abram
 

Recently uploaded (20)

Managing Planning and Development of Citie- 26-2-24.docx
Managing Planning and  Development of  Citie-  26-2-24.docxManaging Planning and  Development of  Citie-  26-2-24.docx
Managing Planning and Development of Citie- 26-2-24.docx
 
Sensitivity Training for 2023 BSKE.pptx
Sensitivity Training for  2023 BSKE.pptxSensitivity Training for  2023 BSKE.pptx
Sensitivity Training for 2023 BSKE.pptx
 
2024: The FAR, Federal Acquisition Regulations - Part 16
2024: The FAR, Federal Acquisition Regulations - Part 162024: The FAR, Federal Acquisition Regulations - Part 16
2024: The FAR, Federal Acquisition Regulations - Part 16
 
PPT Item # 2 -- Announcements Powerpoint
PPT Item # 2 -- Announcements PowerpointPPT Item # 2 -- Announcements Powerpoint
PPT Item # 2 -- Announcements Powerpoint
 
World Happiness Report 2024- Full Report
World Happiness Report 2024- Full ReportWorld Happiness Report 2024- Full Report
World Happiness Report 2024- Full Report
 
Water and peace go hand-in hand. World Water Day 2024
Water and peace go hand-in hand. World Water Day 2024Water and peace go hand-in hand. World Water Day 2024
Water and peace go hand-in hand. World Water Day 2024
 
Living life to the full: How can we make our longer lives healthier, happier ...
Living life to the full: How can we make our longer lives healthier, happier ...Living life to the full: How can we make our longer lives healthier, happier ...
Living life to the full: How can we make our longer lives healthier, happier ...
 
CBO’s Work on Health Care and a Call for New Research
CBO’s Work on Health Care and a Call for New ResearchCBO’s Work on Health Care and a Call for New Research
CBO’s Work on Health Care and a Call for New Research
 
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS: relato de expe...
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS:  relato de expe...O Conselho Estadual de Cultura e o Incentivo à Cultura no RS:  relato de expe...
O Conselho Estadual de Cultura e o Incentivo à Cultura no RS: relato de expe...
 
War in Ukraine and problematics of the Ukrainian refugees in USA
War in Ukraine and problematics of the Ukrainian refugees in USAWar in Ukraine and problematics of the Ukrainian refugees in USA
War in Ukraine and problematics of the Ukrainian refugees in USA
 
Item # 1a - March 18, 2024 Special CCM Minutes
Item # 1a - March 18, 2024 Special CCM MinutesItem # 1a - March 18, 2024 Special CCM Minutes
Item # 1a - March 18, 2024 Special CCM Minutes
 
2024: The FAR, Federal Acquisition Regulations - Part 17
2024: The FAR, Federal Acquisition Regulations - Part 172024: The FAR, Federal Acquisition Regulations - Part 17
2024: The FAR, Federal Acquisition Regulations - Part 17
 
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...
The Federal Perspective on Coverage of Medications to Treat Obesity: Consider...
 
Yes!? We can end TB - World Tuberculosis Day 2024.
Yes!? We can end TB - World Tuberculosis Day 2024.Yes!? We can end TB - World Tuberculosis Day 2024.
Yes!? We can end TB - World Tuberculosis Day 2024.
 
Children who live with Grandparents are really lucky
Children who live with Grandparents are really luckyChildren who live with Grandparents are really lucky
Children who live with Grandparents are really lucky
 
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptx
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptxDB9_BTR_Webinar_Slidedeck_20230320 (1).pptx
DB9_BTR_Webinar_Slidedeck_20230320 (1).pptx
 
Water can create peace or spark conflict.
Water can create peace or spark conflict.Water can create peace or spark conflict.
Water can create peace or spark conflict.
 
Water for Prosperity and peace - United Nations World Water Development Repo...
Water for Prosperity and peace -  United Nations World Water Development Repo...Water for Prosperity and peace -  United Nations World Water Development Repo...
Water for Prosperity and peace - United Nations World Water Development Repo...
 
What Teenagers Have to Say about the Grandparents
What Teenagers Have to Say about the GrandparentsWhat Teenagers Have to Say about the Grandparents
What Teenagers Have to Say about the Grandparents
 
Hub Design Inspiration Graphics for inspiration
Hub Design Inspiration Graphics for inspirationHub Design Inspiration Graphics for inspiration
Hub Design Inspiration Graphics for inspiration
 

Git inside out

Editor's Notes

  1. Take informal survey!
  2. http://typicalprogrammer.com/linus-torvalds-goes-off-on-linux-and-git/ http://www.linuxfoundation.org/news-media/blogs/browse/2012/02/greatness-git
  3. How many people can relate? I often found myself in this situation. Then started learning more & more about Git’s internals. And found myself in this situation less & less. I started talking to other people about it, and, it turns out, they had a similar experience. This is why I want to take a depth-first approach with you folks tonight. I think it’s important to grok Git’s internals in order to be able to reason your way through situations you find yourself in. And I want to share that journey with you this evening.
  4. NEXT: Distributed
  5. Git is egalitarianistic
  6. NEXT: Content addressable
  7. Porcelain vs plumbing
  8. NEXT: Conceptual models
  9. NEXT: Git as a database
  10. Note that the filename isn’t part of the blob
  11. NEXT: Git as a graph
  12. A tree is a DAG iff each child has a single parent. It’s immutable b/c of the key-value store.
  13. NEXT: Dissect Ruby on Rails SVN repo: 115M Ruby on Rails Git repo: 13M
  14. Implemented as writing a 40-byte hash to a file on your file system. This is why branching is blazing fast.
  15. It's a *D*AG. Since new nodes aren't reachable by HEAD, your view of the graph hasn't changed, thus we haven't violated its immutability.
  16. NEXT: Saving yourself series
  17. NEXT: Recap
  18. NEXT: Resources