SlideShare a Scribd company logo
1 of 42
Download to read offline
Introduction to
Surabhi Gupta
Fast, open-source, distributed
source control system.
Client-Server vs Distributed models
VCS SERVER
Version 1
Version 2
Version 3
Version 1 Version 1
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Advantages of Git over P4
Perforce (Client-Server) Git (Distributed)
Version management system Source control system
Slow due to network latency and
increased dependency on server calls
Fast! Work locally, offline
Intermediate work cannot be easily
saved to P4
Various checkpoints for saving
intermediate work
Difficult to experiment Facilitates experimentation
A merger is typically responsible for
merging between branches
The developer is responsible for
merging their branch into master
Server for Git
❖ Github, Stash, CloudForge, etc are code management
and collaboration tools for Git repos!
❖ They provide fine grained control over permissions,
audit of commit history.!
❖ The distributed model of Git facilitates open source
projects since individuals can easily fork off repos and
merge the changes back in.
Scope of the talk
❖ Various roles require different levels of expertise in Git:!
❖ Manager !
❖ Software Engineer/QA Engineer !
❖ Merger/Release Engineer — consumer of git scripts!
❖ Develop scripts that extend git functionality — deep dive into git
internals.!
❖ We will cover concepts and commands that will come in handy in your
day-to-day work as a developer.!
❖ This talk is a road map of the Git world. Hopefully, it will whet your
appetite for exploring the trails.
Roadmap
❖ Content hashing!
❖ Blobs to Branches!
❖ Staging and committing !
❖ Remotes and pull requests!
❖ Merge conflicts!
❖ Git resources
Content Hashing
❖ Contents are referenced using their hashes: !
sha1(“blob ” + fileSize + “0” + fileContent)!
echo “foobar” > foo.txt

git hash-object foo.txt = sha1 (“blob 70foobarn”)!
323fae03f4606ea9991df8befbb2fca795e648fa!
❖ Fun fact: Renames are not stored in the repo. They’re
computed by commands such as git diff, git merge, etc.
Blobs to trees
❖ A tree is an object that stores !
a) blob!
b) subtree!
❖ Each of these contain metadata about their mode, type and
name!
❖ A tree object can contain objects of type “blob” or “tree”.!
❖ Example modes: 100755 means it’s an executable file, 120000
specifies a symbolic link
Git Internals: Tree
blob
blob
tree
Commit from trees
❖ A commit is a pointer to a tree!
❖ It is pointed to by one or more parent commits!
❖ It also contains metadata about its:!
1) Author !
2) Committer
Git Internals: Commit
parent!
commit
tree’
tree blob’
blob
commit
Commits to trees
parent!
commit
commit
tree
tree blob
blob
tree’
blob’
blob
Reuse of objects
tree
tree blob
blob
tree’
blob’
blob
parent!
commit
commit
Reusing blob/tree !
from elsewhere
or
… under-the-hood!
object!
sharing
Reuse of objects within a tree
“B”“A” “C”
“A”
tree
Blobs can be shared within!
a single tree.
Multiple parents
P1 P2
C
Multiple parents
T1
B1
T2
B2
T3
B3
P1 P2
C
Commits with multiple parents!
have a one-to-one relationship with trees, !
similar to commits with single parents
Branch - pointer to a commit
Master
git branch
HEAD - pointer to the current commit
HEAD
git checkout C
Master
HEAD
Master
C C
All your codebase are belong to me
❖ git clone!
❖ git log
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Version 1
Version 2
Version 3
Server/Remote
You Peer
Our first commit
❖ echo “May the 4th” >> “force.txt”!
❖ git status!
❖ git add force.txt!
❖ git diff —cached!
❖ git commit -m “May the force be with you”
C3
C2
C1
C4
C3
master
C2
C1
You
Remote
remotes/master
master
C4
C3
C2
C1
You
git push
Remote
C4
C3
C2
C1
origin/master
master
master
What if I made a mistake?
Undo unstaged changes
force.txt
git checkout — force.txt
echo “new” >> force.txt
Committed
Staging!
Area
Unstaged!
changes
Unstage changes
force.txt
force.txt
git reset HEAD force.txt
git add force.txt
Committed
Staging!
Area
Unstaged!
changes
Uncommit changes
force.txt
force.txt
git reset —soft HEAD^
git commit -m
“Second commit”
Committed
Staging!
Area
Unstaged!
changes
Typical workflow
Typically, if your team has more than one person, you
wouldn’t commit to master directly. Recommended
workflow:!
1) Check out a private branch!
2) Commit to the branch, and regularly push to remote.!
3) When the work is complete, get a code review (likely
via a pull request) and merge the branch into master
Step 1: Create a new branch
git branch bugFix
HEAD
master
bugFix
HEAD
master
Checkout said branch
git checkout bugFix
bugFix
HEAD
master
bugFix
HEAD
master
Current branch
Step 2: Feature development
HEAD
master
B
CbugFix
master
B
CbugFix
D
Local Remote
A A
Step 3: Merge into master
A
master
B
CbugFix
D
Remote
A
masterbugFix
B
E
C
New merge commit E
Remote after!
merge
D
gitk - show git graph
Can we do better?
A
master
B
CbugFix
D
We would like to modify the
commit history to make it
appear as if bugFix was based
on commit D all along!
Rebase to the rescue
❖ Rebase allows you to replay a series of commits on top
of a new base commit. !
❖ Helps keep the commit history clean
Rebase in action
A
master
B
CbugFix
D
bugFix
A
D
C*
B*
git rebase master bugFix
B
C

master
Merge bugFix with master
A
D
E
masterbugFix
A
master
C*
bugFix
B*
D
C*
B*
Merging the rebased branch bugFix !
into master. This merge is typically!
triggered in the code management tool!
(Github, Stash, etc) after a pull request!
is approved.
Merge conflicts
❖ Situation: Conflicting modifications to a file that has
changed since we checked it out!
❖ Two options: merge, rebase!
❖ On a private branch, it is recommended that you rebase. !
❖ On a shared branch, merge is the way to go.
Changing the commit history
❖ “git commit —amend” rewrites the your last commit
with the current changes instead of creating a new
commit!
❖ Interactive rebase: git rebase -i!
❖ Swiss army knife of modifying history!
❖ Allows you to amend, squash, split, or skip commits
as they're applied
Many roads, one destination
❖ There are often multiple ways to accomplish a task in Git, for example:
git branch <branchName>

git checkout <branchName>
 git checkout -b <branchName>
git checkout -b <branchName>
<remoteName>/<remoteBranch>
git branch --track <branchName>
<remoteName>/<remoteBranch>
git fetch!
git merge
git pull
Give It a Try
Git Resources
❖ Learn by playing: http://pcottle.github.io/learnGitBranching/!
❖ Atlassian tutorial: https://www.atlassian.com/git/tutorials/
setting-up-a-repository/!
❖ Free CodeSchool course on Git: https://www.codeschool.com/
courses/git-real!
❖ StackOverflow is a great resource: http://stackoverflow.com/
questions/2706797/finding-what-branch-a-commit-came-from!
❖ Pro Git by Scott Chacon and Ben Straub: http://git-scm.com/
book/en/v2
Closing thoughts
❖ Git is a powerful source control tool designed to
maximize the efficiency of the developer. Take full
advantage of it!!
❖ We’ve only explored the tip of the iceberg. May the
power of Git be with you.

More Related Content

What's hot

Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advancedYodalee
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub태환 김
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parserfukamachi
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Git: a brief introduction
Git: a brief introductionGit: a brief introduction
Git: a brief introductionRandal Schwartz
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsth507
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015mwrather
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsChris Bohatka
 
Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2Vinci Rufus
 

What's hot (20)

Git: basic to advanced
Git: basic to advancedGit: basic to advanced
Git: basic to advanced
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git: a brief introduction
Git: a brief introductionGit: a brief introduction
Git: a brief introduction
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commands
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git basics
Git basicsGit basics
Git basics
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basics
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2
 

Similar to Git basics

Similar to Git basics (20)

Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Source control management
Source control managementSource control management
Source control management
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
 
Session git
Session gitSession git
Session git
 
Git & gitflow
Git & gitflowGit & gitflow
Git & gitflow
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Version Control ThinkVitamin
Version Control ThinkVitaminVersion Control ThinkVitamin
Version Control ThinkVitamin
 
3 Git
3 Git3 Git
3 Git
 
Git training
Git trainingGit training
Git training
 
Git basic
Git basicGit basic
Git basic
 
Git presentation
Git presentationGit presentation
Git presentation
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
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
 

Recently uploaded

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Recently uploaded (20)

Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

Git basics

  • 3. Client-Server vs Distributed models VCS SERVER Version 1 Version 2 Version 3 Version 1 Version 1 Version 1 Version 2 Version 3 Version 1 Version 2 Version 3 Version 1 Version 2 Version 3
  • 4. Advantages of Git over P4 Perforce (Client-Server) Git (Distributed) Version management system Source control system Slow due to network latency and increased dependency on server calls Fast! Work locally, offline Intermediate work cannot be easily saved to P4 Various checkpoints for saving intermediate work Difficult to experiment Facilitates experimentation A merger is typically responsible for merging between branches The developer is responsible for merging their branch into master
  • 5. Server for Git ❖ Github, Stash, CloudForge, etc are code management and collaboration tools for Git repos! ❖ They provide fine grained control over permissions, audit of commit history.! ❖ The distributed model of Git facilitates open source projects since individuals can easily fork off repos and merge the changes back in.
  • 6. Scope of the talk ❖ Various roles require different levels of expertise in Git:! ❖ Manager ! ❖ Software Engineer/QA Engineer ! ❖ Merger/Release Engineer — consumer of git scripts! ❖ Develop scripts that extend git functionality — deep dive into git internals.! ❖ We will cover concepts and commands that will come in handy in your day-to-day work as a developer.! ❖ This talk is a road map of the Git world. Hopefully, it will whet your appetite for exploring the trails.
  • 7. Roadmap ❖ Content hashing! ❖ Blobs to Branches! ❖ Staging and committing ! ❖ Remotes and pull requests! ❖ Merge conflicts! ❖ Git resources
  • 8. Content Hashing ❖ Contents are referenced using their hashes: ! sha1(“blob ” + fileSize + “0” + fileContent)! echo “foobar” > foo.txt
 git hash-object foo.txt = sha1 (“blob 70foobarn”)! 323fae03f4606ea9991df8befbb2fca795e648fa! ❖ Fun fact: Renames are not stored in the repo. They’re computed by commands such as git diff, git merge, etc.
  • 9. Blobs to trees ❖ A tree is an object that stores ! a) blob! b) subtree! ❖ Each of these contain metadata about their mode, type and name! ❖ A tree object can contain objects of type “blob” or “tree”.! ❖ Example modes: 100755 means it’s an executable file, 120000 specifies a symbolic link
  • 11. Commit from trees ❖ A commit is a pointer to a tree! ❖ It is pointed to by one or more parent commits! ❖ It also contains metadata about its:! 1) Author ! 2) Committer
  • 13. Commits to trees parent! commit commit tree tree blob blob tree’ blob’ blob
  • 14. Reuse of objects tree tree blob blob tree’ blob’ blob parent! commit commit Reusing blob/tree ! from elsewhere or … under-the-hood! object! sharing
  • 15. Reuse of objects within a tree “B”“A” “C” “A” tree Blobs can be shared within! a single tree.
  • 17. Multiple parents T1 B1 T2 B2 T3 B3 P1 P2 C Commits with multiple parents! have a one-to-one relationship with trees, ! similar to commits with single parents
  • 18. Branch - pointer to a commit Master git branch
  • 19. HEAD - pointer to the current commit HEAD git checkout C Master HEAD Master C C
  • 20. All your codebase are belong to me ❖ git clone! ❖ git log Version 1 Version 2 Version 3 Version 1 Version 2 Version 3 Version 1 Version 2 Version 3 Server/Remote You Peer
  • 21. Our first commit ❖ echo “May the 4th” >> “force.txt”! ❖ git status! ❖ git add force.txt! ❖ git diff —cached! ❖ git commit -m “May the force be with you”
  • 24. What if I made a mistake?
  • 25. Undo unstaged changes force.txt git checkout — force.txt echo “new” >> force.txt Committed Staging! Area Unstaged! changes
  • 26. Unstage changes force.txt force.txt git reset HEAD force.txt git add force.txt Committed Staging! Area Unstaged! changes
  • 27. Uncommit changes force.txt force.txt git reset —soft HEAD^ git commit -m “Second commit” Committed Staging! Area Unstaged! changes
  • 28. Typical workflow Typically, if your team has more than one person, you wouldn’t commit to master directly. Recommended workflow:! 1) Check out a private branch! 2) Commit to the branch, and regularly push to remote.! 3) When the work is complete, get a code review (likely via a pull request) and merge the branch into master
  • 29. Step 1: Create a new branch git branch bugFix HEAD master bugFix HEAD master
  • 30. Checkout said branch git checkout bugFix bugFix HEAD master bugFix HEAD master Current branch
  • 31. Step 2: Feature development HEAD master B CbugFix master B CbugFix D Local Remote A A
  • 32. Step 3: Merge into master A master B CbugFix D Remote A masterbugFix B E C New merge commit E Remote after! merge D gitk - show git graph
  • 33. Can we do better? A master B CbugFix D We would like to modify the commit history to make it appear as if bugFix was based on commit D all along!
  • 34. Rebase to the rescue ❖ Rebase allows you to replay a series of commits on top of a new base commit. ! ❖ Helps keep the commit history clean
  • 36. Merge bugFix with master A D E masterbugFix A master C* bugFix B* D C* B* Merging the rebased branch bugFix ! into master. This merge is typically! triggered in the code management tool! (Github, Stash, etc) after a pull request! is approved.
  • 37. Merge conflicts ❖ Situation: Conflicting modifications to a file that has changed since we checked it out! ❖ Two options: merge, rebase! ❖ On a private branch, it is recommended that you rebase. ! ❖ On a shared branch, merge is the way to go.
  • 38. Changing the commit history ❖ “git commit —amend” rewrites the your last commit with the current changes instead of creating a new commit! ❖ Interactive rebase: git rebase -i! ❖ Swiss army knife of modifying history! ❖ Allows you to amend, squash, split, or skip commits as they're applied
  • 39. Many roads, one destination ❖ There are often multiple ways to accomplish a task in Git, for example: git branch <branchName>
 git checkout <branchName>
 git checkout -b <branchName> git checkout -b <branchName> <remoteName>/<remoteBranch> git branch --track <branchName> <remoteName>/<remoteBranch> git fetch! git merge git pull
  • 40. Give It a Try
  • 41. Git Resources ❖ Learn by playing: http://pcottle.github.io/learnGitBranching/! ❖ Atlassian tutorial: https://www.atlassian.com/git/tutorials/ setting-up-a-repository/! ❖ Free CodeSchool course on Git: https://www.codeschool.com/ courses/git-real! ❖ StackOverflow is a great resource: http://stackoverflow.com/ questions/2706797/finding-what-branch-a-commit-came-from! ❖ Pro Git by Scott Chacon and Ben Straub: http://git-scm.com/ book/en/v2
  • 42. Closing thoughts ❖ Git is a powerful source control tool designed to maximize the efficiency of the developer. Take full advantage of it!! ❖ We’ve only explored the tip of the iceberg. May the power of Git be with you.