SlideShare a Scribd company logo
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 advanced
Yodalee
 
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
fukamachi
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git: a brief introduction
Git: a brief introductionGit: a brief introduction
Git: a brief introduction
Randal Schwartz
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
Sage Sharp
 
Git vs svn
Git vs svnGit vs svn
Git vs svn
Suman Mukherjee
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
Paulo Henrique Nonaka
 
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
th507
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Pham Quy (Jack)
 
Git basics
Git basicsGit basics
Git basics
Ashwin Date
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
mwrather
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
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
Chris Bohatka
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
Sébastien Saunier
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
Pranav Kulkarni
 
Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2Re-thinking Performance tuning with HTTP2
Re-thinking Performance tuning with HTTP2
Vinci 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

Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 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 GitRobert Lee-Cann
 
Source control management
Source control managementSource control management
Source control management
Owen Winkler
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
Shinho Kang
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
KeerthanaJ32
 
Session git
Session gitSession git
Session git
Roni Saha
 
Git & gitflow
Git & gitflowGit & gitflow
Git & gitflow
Nolifelover Earn
 
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
Katie Sylor-Miller
 
Version Control ThinkVitamin
Version Control ThinkVitaminVersion Control ThinkVitamin
Version Control ThinkVitamin
Alex Hillman
 
3 Git
3 Git3 Git
Git training
Git trainingGit training
Git training
Jérémy Gobet
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Git presentation
Git presentationGit presentation
Git presentation
James Cuzella
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
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
RaghavendraVattikuti1
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
Alberto Leal
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
BruceLee275640
 
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
 

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

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

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.