SlideShare ist ein Scribd-Unternehmen logo
1 von 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”

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Git training v10
Git training v10Git training v10
Git training v10
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git slides
Git slidesGit slides
Git slides
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git
GitGit
Git
 

Ähnlich wie 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
 
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
 
From Windows to Linux: Converting a Distributed Perforce Helix Infrastructure
From Windows to Linux: Converting a Distributed Perforce Helix InfrastructureFrom Windows to Linux: Converting a Distributed Perforce Helix Infrastructure
From Windows to Linux: Converting a Distributed Perforce Helix InfrastructurePerforce
 

Ähnlich wie 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
 
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
 
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
 
From Windows to Linux: Converting a Distributed Perforce Helix Infrastructure
From Windows to Linux: Converting a Distributed Perforce Helix InfrastructureFrom Windows to Linux: Converting a Distributed Perforce Helix Infrastructure
From Windows to Linux: Converting a Distributed Perforce Helix Infrastructure
 
Talk to git
Talk to gitTalk to git
Talk to git
 

Kürzlich hochgeladen

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
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.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
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
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Kürzlich hochgeladen (20)

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
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...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
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
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

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”

Hinweis der Redaktion

  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