SlideShare une entreprise Scribd logo
1  sur  56
Basic Git Into 
JivyGroup 2014 
yoad@jivygroup.com
Why Git and not X? 
• You can find many comparisons and 
discussions on line.. Will not talk about this 
here much 
• Yes, Git is Hard since it’s Complex. 
• It’s complex in order to be flexible and 
powerful 
• Yes, SVN is simpler, until you need to do 
something complicated
Why Git and not X? 
If simple was the only thing that matters we 
would still…
SVN Model 
The Server 
User2 
Repo2 
Commit 
User2 
Repo1 
Checkout 
Update 
commit 
trunk Branches 
trunk Branches/b1 
trunk 
User1 
Repo1 
b1 
root
GIT Model 
The Server (just Another Repo) 
User2 Repo 
master branch1 
Clone 
Pull 
origin/master 
origin/master 
User1 Repo 
mybranch 
branch123 
branch4b5r6anch123 
push 
push 
branch2 
origin/branch2 
Clone 
Pull 
Pull 
User2/branch456 
push 
Who is server 
and who is 
client?
Local Git 
Single repository concepts 
LOCAL
Basic Definitions 
• Repository 
– Collection of files and their history organized in 
folders, branches, tags 
– Is stored in a normal file system somewhere 
– Can be on a local machine or a remote machine 
– To work with GIT you will need a repo somewhere 
– When creating a new one… it’s empty 
Example 1
Basic Definitions 
• Workspace 
– Where you do work.. 
• Index 
– Snapshot of files in the workspace (can be some of 
them. 
– You add to the index files you change / remove etc. 
• Commit 
– A snapshot of the workspace at some point 
– Has unique revision number 
– Knows the commit (commits) that it’s based on
workspace index 
Repository 
store 
changes 
staged add 
changes 
staged add 
Committed and generated unique commit 
rev. number
Simple Local GIT 
Work 
Add To Index 
Commit 
• Add / Remove 
• Change Files 
• Add (same as “stage”) the changes 
• Not all files must be staged 
• Can stage changes to same file several times 
• Think “snapshot” of the work 
• Changes from the index stored 
• Get a unique rev. number 
• Index emptied 
Example 2
Branches 
• Branch is a pointer to a commit 
• A branch can point at other commits – it can 
move 
• A branch is a way to organize working histories 
• Since commits know which commits they are 
based on – branch represents a commit and 
what came before it.
Branches 
• When doing a “commit” the current “branch” 
moves to point at the new commit 
bx C3 C2 C1 
On branch bx -> Commit of C4 
bx C4 C3 C2 C1 
Example 3
Branches 
• Here is a branch 
bx C3 C2 C1 
• Creating a new branch just adds another 
“pointer” to the same commit 
C3 C2 C1 
bx 
by 
Example 3
Branches 
• Other branches are not affected by a commit 
C3 C2 C1 
bx 
by 
On branch bx -> Commit of C4 
C3 C2 C1 
bx 
C4 
by 
Example 3
Branches 
• Checking out a branch puts the snapshot (the 
commit) it points to into the workspace 
workspace index 
Repository 
store 
Checkout branch y 
Branch y 
snapshot 
Branch x 
snapshot 
Now on branch y 
Example 3
Branches 
• master – is just another branch, but is the 
default one which gets created. (So you will 
always see it in a repo) 
• Branching is cheap – feel free to branch a lot. 
• Branch is a good way to work on multiple 
things in parallel
Merging 
• Combining one ore more branches into the 
current branch 
• Allows changes from other branches to be 
integrated into the current work history 
• Usually generates a new commit which has 
more than one predecessor 
• Other branches not affected
Merging 
C3 C2 C1 
bx 
by 
C4 
C5 
Merging bx into by 
C3 C2 C1 
bx C4 
by C6 
C5
Merging 
• The branch “bx” was not affected 
• Merge only changes the workspace. Still need 
to add (to index) and commit (“by”) to 
actually generate “c6” 
C3 C2 C1 
bx C4 
by C6 C5
Merging - Conflicts 
• When merging, if there are conflicts - need to 
solve them. 
• After solving, need to “add” the changes and 
commit the merged workspace 
C3 C2 C1 
Example 3 
bx C4 
by C6 C5
Merging – fast forward 
• Fast Forward – a type of merge which only 
requires moving the “branch” pointer 
• Possible when the current branch is an 
ancestor of the merged branch 
• No new “merge” commits need to be created
Merging – fast forward 
bx C3 C2 C1 
by 
C4 
Merging bx into by 
bx C3 C2 C1 
by 
C4 
C4 is based on C3 so 
“by” which points to 
C3 can move to 
point to C4 
Example 4
Merging – fast forward 
C3 C2 C1 
bx 
by 
C4 
C4 is not based on 
C5, so cannot fast 
forward. 
C5 
C3 C2 C1 
bx 
by 
C4 
C5 
C6 
Now its possible to ff by 
In that case, merge…
Remote 
More than one repository 
REMOTE
Collaborating 
• Clone – creates a local repository by copying 
another (remote) repository 
• Repositories which were cloned can exchange 
changes between them 
• Pull? For now forget about it. we will come 
back to it later 
• Commits are always local. But can be sent to 
other repositories.
Fetch 
• Fetch – gets changes from a remote repository 
that you don’t already have. 
• Fetch gets the changes to the local repository 
but does not touch the index or workspace. 
• After a fetch, usually a merge needs to take 
place (more on this later)
Remote Branches - fetch 
• Remote branches represent the state of a 
branch on the repository it is fetched from 
• It is like another branch when it comes to 
merging from 
• You cannot checkout a remote branch, you 
branch it (create a local pointer to it) 
• After fetching, a remote branch and it’s local 
branch counterpart may need to be merged
Remote Branches 
My Machine The Server 
master 
C1 
C0 
C1 clone 
origin/master 
C0 
master 
This is a remote 
branch 
origin is just a name 
for a “remote” 
Example 5
Remote Branches - fetch 
My Machine The Server 
Some changes on 
the server 
master 
C1 C2 
C1 
C0 
origin/master 
C0 
master 
fetch
Remote Branches - fetch 
My Machine The Server 
master 
C2 
C1 
C0 
origin/master 
C2 master 
C1 
C0 
Example 5
Remote Branches - fetch 
My Machine The Server 
master 
C2 master 
C1 C2 
C1 
C0 
origin/master 
C0 
Can 
merge!
Remote Branches - fetch 
My Machine The Server 
master 
C2 
C1 
C0 
origin/master 
C1 
C0 
master 
C2 
Now 
merged 
(fast 
forward in 
this case) 
Example 5
push 
• Will take local objects (commits, tags) which 
are required to make a remote branch 
complete – and send them. 
• Will merge those local changes into the 
remote branch 
• Will only do a “fast-forward” merge (other 
merge type, if required, will fail the push)
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C3 
C2 
C1 
origin/master 
C0 
This commit is not 
on the remote 
master
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C3 
C2 
C1 
origin/master 
C0 
push
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C2 
C1 
origin/master 
C0 
Now merged and in 
a fast forward 
manner 
C3 C3 
Example 5
push 
• If cannot do a fast-forward – will fail. Then, a 
fetch + merge is required to allow the push. 
• Once remote changes merged locally again a 
fast forward is possible and the push would 
work.
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C2 
C1 
origin/master 
C0 
This commit is not 
on the remote 
master 
C3 C4 
This commit is not 
on the local master 
But local 
origin/master does 
not know…
Remote Branches - Push 
My Machine The Server 
master 
C3 C4 
C2 
C1 
C0 
master 
C2 
C1 
origin/master 
C0 
No can do, fetch + 
merge first. 
push
Remote Branches - Push 
My Machine The Server 
master 
C3 C4 
C2 
C1 
C0 
master 
C2 
C1 
origin/master 
C0 
fetch
Remote Branches - Push 
My Machine The Server 
master 
C3 C4 
C2 
C1 
C0 
master 
C2 
C1 
origin/master 
C0 
C4 
The commit from 
the remote arrived 
This is what the 
remote knows about 
the master branch
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C3 
C2 
C1 
origin/master 
C0 
C4 
C4 
C5 
Now 
merged 
to local 
master
Remote Branches - Push 
My Machine The Server 
master 
C2 
C1 
C0 
master 
C3 
C2 
C1 
origin/master 
C0 
C4 
C4 
C5 
push
Remote Branches - Push 
My Machine The Server 
master 
C3 
C2 
C1 
origin/master 
C0 
C4 
C5 
Now 
merged 
since fast 
forward is 
possible 
master 
C3 
C2 
C1 
C0 
C4 
C5 
The commits from 
the local arrived 
Example 6
Remote Branches 
• Reminder - Remote branches represent a 
branch on a remote repository 
• The branch origin/master for example is a 
local pointer to the “master” on “origin” 
• It reflects what the local repository currently 
knows about the state of “master” on “origin” 
• You cannot change them, but you can 
“checkout” to get a “remote tracking branch”
Remote Tracking Branches 
• A local branch which is configured to “track” a 
remote branch 
• Will allow commands like “fetch” and “push” 
to know where to send/get changes 
• Just a helper, you could specify all the 
locations in the command args 
• Helpful also to remember where a local 
branch points to
Remote Tracking Branches 
• When cloning a remote repo will check out 
the remote “master” 
• “origin” is default name for the remote you 
cloned from 
• So “origin/master” is the remote branch and 
“master” is configured to track it 
• master is a remote tracking branch
Remote Branches Summary 
My Machine The Server 
remote: srv1 -> https://the.server/... 
branch1 
tracks 
Cx srv1/branch1 
branch1 
Cx 
points at 
Local state of 
Cy Cy 
created 
when “fetch” 
from srv1 
Created when 
“checkout” 
srv1/branch1
pull 
• Now it’s time to talk about pull since it’s just a 
shortcut command to do: 
1. Fetch from a remote 
2. Merge changes from “remote branch” into the 
“remote tracking branch” 
• Sometimes the tool would also allow to 
“commit” merges for you right after the pull 
(not part of pull, but a helper)
Summary of operations 
workspace index 
Repository 
store 
clone 
Remote 
Repository 
checkout 
add 
push 
commit 
merge fetch 
Pull (fetch+merge)
Rebase 
• Instead of merging, replays set of changes on 
top of another branch 
• Affects the “rebased” branch only 
• Changes the history of commits 
• Can be dangerous 
• Very useful to remove history clutter 
• Simple rule, use locally only and for branches 
which you will never share
Rebase 
C2 
bx 
by 
C4 
C3 
C2 
Merge bx into by 
bx 
by 
C4 
C5 C3 
C2 
Rebase by on bx 
bx 
by 
C4 
C3’ C3 
Committing will have c4 
as the only ancestor of 
c3’ 
Committing will have c4 
and c3 as two ancestors 
of c5 
Note: In both cases can now fast-forward bx
Rebase – when to use 
• You have a local branch – has some changes 
committed to it 
• Fetched a remote branch 
• Instead of merging into remote branch – 
rebase on it 
• Now merge (fast forward) into the remote 
branch 
• Push happilly 
Example 7
We did not discuss 
• The “Pull Request” 
• Suggested work flow for small teams 
• GitHub and BitBucket 
Go learn more…
Summary 
• Git is complex, but flexible and powerful 
• Git supports distributed teams very well and 
also is the standard de-facto for OSS projects 
• Due to it’s flexibility, every team needs to 
decide on the workflow which works best for 
it
How to know more 
• Read the Git Pro Book 
• No really, its very good, explains most of the 
stuff well 
• Look for blog posts with titles like “how I got 
started with git”

Contenu connexe

Tendances

Tendances (20)

Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git basic
Git basicGit basic
Git basic
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Github basics
Github basicsGithub basics
Github basics
 
Learning git
Learning gitLearning git
Learning git
 
Introducing GitLab (June 2018)
Introducing GitLab (June 2018)Introducing GitLab (June 2018)
Introducing GitLab (June 2018)
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Git basics
Git basicsGit basics
Git basics
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Introduction to GitHub
Introduction to GitHubIntroduction to GitHub
Introduction to GitHub
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git flow Introduction
Git flow IntroductionGit flow Introduction
Git flow Introduction
 

Similaire à Basic Git Intro

Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Paradigma Digital
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Ahmed El-Arabawy
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub태환 김
 
Introduce to Git and Jenkins
Introduce to Git and JenkinsIntroduce to Git and Jenkins
Introduce to Git and JenkinsAn Nguyen
 
DVCS branching (with mercurial)
DVCS branching (with mercurial)DVCS branching (with mercurial)
DVCS branching (with mercurial)David Vega
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Version Control ThinkVitamin
Version Control ThinkVitaminVersion Control ThinkVitamin
Version Control ThinkVitaminAlex Hillman
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanJames Ford
 
Clarive 7 Branching Model
Clarive 7 Branching ModelClarive 7 Branching Model
Clarive 7 Branching ModelClarive
 

Similaire à Basic Git Intro (20)

Working with Git
Working with GitWorking with Git
Working with Git
 
Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?Git vs Subversion: ¿Cuando elegir uno u otro?
Git vs Subversion: ¿Cuando elegir uno u otro?
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git
GitGit
Git
 
Switching to Git
Switching to GitSwitching to Git
Switching to Git
 
Version control 101
Version control 101Version control 101
Version control 101
 
Git more done
Git more doneGit more done
Git more done
 
Introduce to Git and Jenkins
Introduce to Git and JenkinsIntroduce to Git and Jenkins
Introduce to Git and Jenkins
 
GIT-Lesson-1
GIT-Lesson-1GIT-Lesson-1
GIT-Lesson-1
 
Working with Git
Working with GitWorking with Git
Working with Git
 
DVCS branching (with mercurial)
DVCS branching (with mercurial)DVCS branching (with mercurial)
DVCS branching (with mercurial)
 
Git Branch
Git BranchGit Branch
Git Branch
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Version Control ThinkVitamin
Version Control ThinkVitaminVersion Control ThinkVitamin
Version Control ThinkVitamin
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Git
GitGit
Git
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
 
Git 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawanGit 101: Force-sensitive to Jedi padawan
Git 101: Force-sensitive to Jedi padawan
 
Clarive 7 Branching Model
Clarive 7 Branching ModelClarive 7 Branching Model
Clarive 7 Branching Model
 

Dernier

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
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
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Dernier (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
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 🔝✔️✔️
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Basic Git Intro

  • 1. Basic Git Into JivyGroup 2014 yoad@jivygroup.com
  • 2. Why Git and not X? • You can find many comparisons and discussions on line.. Will not talk about this here much • Yes, Git is Hard since it’s Complex. • It’s complex in order to be flexible and powerful • Yes, SVN is simpler, until you need to do something complicated
  • 3. Why Git and not X? If simple was the only thing that matters we would still…
  • 4. SVN Model The Server User2 Repo2 Commit User2 Repo1 Checkout Update commit trunk Branches trunk Branches/b1 trunk User1 Repo1 b1 root
  • 5. GIT Model The Server (just Another Repo) User2 Repo master branch1 Clone Pull origin/master origin/master User1 Repo mybranch branch123 branch4b5r6anch123 push push branch2 origin/branch2 Clone Pull Pull User2/branch456 push Who is server and who is client?
  • 6. Local Git Single repository concepts LOCAL
  • 7. Basic Definitions • Repository – Collection of files and their history organized in folders, branches, tags – Is stored in a normal file system somewhere – Can be on a local machine or a remote machine – To work with GIT you will need a repo somewhere – When creating a new one… it’s empty Example 1
  • 8. Basic Definitions • Workspace – Where you do work.. • Index – Snapshot of files in the workspace (can be some of them. – You add to the index files you change / remove etc. • Commit – A snapshot of the workspace at some point – Has unique revision number – Knows the commit (commits) that it’s based on
  • 9. workspace index Repository store changes staged add changes staged add Committed and generated unique commit rev. number
  • 10. Simple Local GIT Work Add To Index Commit • Add / Remove • Change Files • Add (same as “stage”) the changes • Not all files must be staged • Can stage changes to same file several times • Think “snapshot” of the work • Changes from the index stored • Get a unique rev. number • Index emptied Example 2
  • 11. Branches • Branch is a pointer to a commit • A branch can point at other commits – it can move • A branch is a way to organize working histories • Since commits know which commits they are based on – branch represents a commit and what came before it.
  • 12. Branches • When doing a “commit” the current “branch” moves to point at the new commit bx C3 C2 C1 On branch bx -> Commit of C4 bx C4 C3 C2 C1 Example 3
  • 13. Branches • Here is a branch bx C3 C2 C1 • Creating a new branch just adds another “pointer” to the same commit C3 C2 C1 bx by Example 3
  • 14. Branches • Other branches are not affected by a commit C3 C2 C1 bx by On branch bx -> Commit of C4 C3 C2 C1 bx C4 by Example 3
  • 15. Branches • Checking out a branch puts the snapshot (the commit) it points to into the workspace workspace index Repository store Checkout branch y Branch y snapshot Branch x snapshot Now on branch y Example 3
  • 16. Branches • master – is just another branch, but is the default one which gets created. (So you will always see it in a repo) • Branching is cheap – feel free to branch a lot. • Branch is a good way to work on multiple things in parallel
  • 17. Merging • Combining one ore more branches into the current branch • Allows changes from other branches to be integrated into the current work history • Usually generates a new commit which has more than one predecessor • Other branches not affected
  • 18. Merging C3 C2 C1 bx by C4 C5 Merging bx into by C3 C2 C1 bx C4 by C6 C5
  • 19. Merging • The branch “bx” was not affected • Merge only changes the workspace. Still need to add (to index) and commit (“by”) to actually generate “c6” C3 C2 C1 bx C4 by C6 C5
  • 20. Merging - Conflicts • When merging, if there are conflicts - need to solve them. • After solving, need to “add” the changes and commit the merged workspace C3 C2 C1 Example 3 bx C4 by C6 C5
  • 21. Merging – fast forward • Fast Forward – a type of merge which only requires moving the “branch” pointer • Possible when the current branch is an ancestor of the merged branch • No new “merge” commits need to be created
  • 22. Merging – fast forward bx C3 C2 C1 by C4 Merging bx into by bx C3 C2 C1 by C4 C4 is based on C3 so “by” which points to C3 can move to point to C4 Example 4
  • 23. Merging – fast forward C3 C2 C1 bx by C4 C4 is not based on C5, so cannot fast forward. C5 C3 C2 C1 bx by C4 C5 C6 Now its possible to ff by In that case, merge…
  • 24. Remote More than one repository REMOTE
  • 25. Collaborating • Clone – creates a local repository by copying another (remote) repository • Repositories which were cloned can exchange changes between them • Pull? For now forget about it. we will come back to it later • Commits are always local. But can be sent to other repositories.
  • 26. Fetch • Fetch – gets changes from a remote repository that you don’t already have. • Fetch gets the changes to the local repository but does not touch the index or workspace. • After a fetch, usually a merge needs to take place (more on this later)
  • 27. Remote Branches - fetch • Remote branches represent the state of a branch on the repository it is fetched from • It is like another branch when it comes to merging from • You cannot checkout a remote branch, you branch it (create a local pointer to it) • After fetching, a remote branch and it’s local branch counterpart may need to be merged
  • 28. Remote Branches My Machine The Server master C1 C0 C1 clone origin/master C0 master This is a remote branch origin is just a name for a “remote” Example 5
  • 29. Remote Branches - fetch My Machine The Server Some changes on the server master C1 C2 C1 C0 origin/master C0 master fetch
  • 30. Remote Branches - fetch My Machine The Server master C2 C1 C0 origin/master C2 master C1 C0 Example 5
  • 31. Remote Branches - fetch My Machine The Server master C2 master C1 C2 C1 C0 origin/master C0 Can merge!
  • 32. Remote Branches - fetch My Machine The Server master C2 C1 C0 origin/master C1 C0 master C2 Now merged (fast forward in this case) Example 5
  • 33. push • Will take local objects (commits, tags) which are required to make a remote branch complete – and send them. • Will merge those local changes into the remote branch • Will only do a “fast-forward” merge (other merge type, if required, will fail the push)
  • 34. Remote Branches - Push My Machine The Server master C2 C1 C0 master C3 C2 C1 origin/master C0 This commit is not on the remote master
  • 35. Remote Branches - Push My Machine The Server master C2 C1 C0 master C3 C2 C1 origin/master C0 push
  • 36. Remote Branches - Push My Machine The Server master C2 C1 C0 master C2 C1 origin/master C0 Now merged and in a fast forward manner C3 C3 Example 5
  • 37. push • If cannot do a fast-forward – will fail. Then, a fetch + merge is required to allow the push. • Once remote changes merged locally again a fast forward is possible and the push would work.
  • 38. Remote Branches - Push My Machine The Server master C2 C1 C0 master C2 C1 origin/master C0 This commit is not on the remote master C3 C4 This commit is not on the local master But local origin/master does not know…
  • 39. Remote Branches - Push My Machine The Server master C3 C4 C2 C1 C0 master C2 C1 origin/master C0 No can do, fetch + merge first. push
  • 40. Remote Branches - Push My Machine The Server master C3 C4 C2 C1 C0 master C2 C1 origin/master C0 fetch
  • 41. Remote Branches - Push My Machine The Server master C3 C4 C2 C1 C0 master C2 C1 origin/master C0 C4 The commit from the remote arrived This is what the remote knows about the master branch
  • 42. Remote Branches - Push My Machine The Server master C2 C1 C0 master C3 C2 C1 origin/master C0 C4 C4 C5 Now merged to local master
  • 43. Remote Branches - Push My Machine The Server master C2 C1 C0 master C3 C2 C1 origin/master C0 C4 C4 C5 push
  • 44. Remote Branches - Push My Machine The Server master C3 C2 C1 origin/master C0 C4 C5 Now merged since fast forward is possible master C3 C2 C1 C0 C4 C5 The commits from the local arrived Example 6
  • 45. Remote Branches • Reminder - Remote branches represent a branch on a remote repository • The branch origin/master for example is a local pointer to the “master” on “origin” • It reflects what the local repository currently knows about the state of “master” on “origin” • You cannot change them, but you can “checkout” to get a “remote tracking branch”
  • 46. Remote Tracking Branches • A local branch which is configured to “track” a remote branch • Will allow commands like “fetch” and “push” to know where to send/get changes • Just a helper, you could specify all the locations in the command args • Helpful also to remember where a local branch points to
  • 47. Remote Tracking Branches • When cloning a remote repo will check out the remote “master” • “origin” is default name for the remote you cloned from • So “origin/master” is the remote branch and “master” is configured to track it • master is a remote tracking branch
  • 48. Remote Branches Summary My Machine The Server remote: srv1 -> https://the.server/... branch1 tracks Cx srv1/branch1 branch1 Cx points at Local state of Cy Cy created when “fetch” from srv1 Created when “checkout” srv1/branch1
  • 49. pull • Now it’s time to talk about pull since it’s just a shortcut command to do: 1. Fetch from a remote 2. Merge changes from “remote branch” into the “remote tracking branch” • Sometimes the tool would also allow to “commit” merges for you right after the pull (not part of pull, but a helper)
  • 50. Summary of operations workspace index Repository store clone Remote Repository checkout add push commit merge fetch Pull (fetch+merge)
  • 51. Rebase • Instead of merging, replays set of changes on top of another branch • Affects the “rebased” branch only • Changes the history of commits • Can be dangerous • Very useful to remove history clutter • Simple rule, use locally only and for branches which you will never share
  • 52. Rebase C2 bx by C4 C3 C2 Merge bx into by bx by C4 C5 C3 C2 Rebase by on bx bx by C4 C3’ C3 Committing will have c4 as the only ancestor of c3’ Committing will have c4 and c3 as two ancestors of c5 Note: In both cases can now fast-forward bx
  • 53. Rebase – when to use • You have a local branch – has some changes committed to it • Fetched a remote branch • Instead of merging into remote branch – rebase on it • Now merge (fast forward) into the remote branch • Push happilly Example 7
  • 54. We did not discuss • The “Pull Request” • Suggested work flow for small teams • GitHub and BitBucket Go learn more…
  • 55. Summary • Git is complex, but flexible and powerful • Git supports distributed teams very well and also is the standard de-facto for OSS projects • Due to it’s flexibility, every team needs to decide on the workflow which works best for it
  • 56. How to know more • Read the Git Pro Book • No really, its very good, explains most of the stuff well • Look for blog posts with titles like “how I got started with git”

Notes de l'éditeur

  1. Show stuff from here: http://www.slideshare.net/jomikr/quick-introduction-to-git?next_slideshow=1 http://www.slideshare.net/lfittl/introduction-to-git-4642204