SlideShare a Scribd company logo
6
Most read
12
Most read
13
Most read
Git Branch
Wei-Tsung Su (蘇維宗)
ellington.su@gmail.com
11/23/2017 (Ver. 1.0)
Ubiquitous Computing and Ambient Networking Laboratory Page : 1
Change Log
Date Ver. Authors Description
11/23/2017 V1.0 Wei-Tsung Su Baseline
Ubiquitous Computing and Ambient Networking Laboratory 2
Reference
• Scott Chacon, Git Pro, Jul. 29, 2009. Available:
http://git-scm.com/book
Ubiquitous Computing and Ambient Networking Laboratory Page : 3
Agenda
• What is branch?
• Why using branch?
• Operations
– Create and checkout a branch
– Merge two branches
– Remove conflicts
– Rebase branch on the other one
– Delete a branch
• Git Workflow
• GitHub Workflow
• Demonstration
Ubiquitous Computing and Ambient Networking Laboratory Page : 4
What is branch?
• Branching model is referred as a killer feature of Git.
• Git commit data structure
– Point master is a branch pointing to a specific snapshot.
– Point HEAD is pointing to current working branch.
Ubiquitous Computing and Ambient Networking Laboratory Page : 5
commit
tree
Snapshot A
blob
File 3
blob
File 2
blob
File 1
commit
tree
Snapshot B
commit
tree
Snapshot C
master HEAD
blob
File 1
(modified)
Compressed
Why using branch?
• Case 1
– Issue fixing without polluting stable version.
– Merge is required after issue has been fixed.
• Case 2
– Creating different product lines for various platforms,
customers, etc.
– Merge may or may not be required.
• Others
Ubiquitous Computing and Ambient Networking Laboratory Page : 6
Create and checkout a Branch
• Create a new branch
– git branch [name]
• Checkout a branch (move HEAD to a branch)
– git checkout [name]
• Create and checkout a new branch
– git checkout –b [name]
Ubiquitous Computing and Ambient Networking Laboratory Page : 7
Merge two branches
• Assume merge branch B into branch A
– # git checkout A
– # git merge B
• However, there may be conflicts while merging
two branches. That is, the same part of the file is
changed differently in two branches.
Ubiquitous Computing and Ambient Networking Laboratory Page : 8
Remove Conflict
• Step 1. check the files which have conflicts
<<<<<<< HEAD:index.html
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53:index.html
• Step 2. remove conflicts manually
• Step 3. commit changes
– # git commit
Ubiquitous Computing and Ambient Networking Laboratory Page : 9
Rebase branch on the other one
• Assume rebase branch B on branch A
– # git checkout B
– # git rebase A
• Similarly, remove conflicts if rebasing a branch on the other one.
– Abort rebasing
• # git rebase --abort
– Continue rebasing
– # git add .
– # git rebase --continue
– # git checkout A
– # git merge B
• Note
– DO NOT rebase the commits that are pushed to public repository.
Ubiquitous Computing and Ambient Networking Laboratory Page : 10
Merge v.s. Rebase
Ubiquitous Computing and Ambient Networking Laboratory Page : 11
S1 S3
S2
A
B
Before merge or rebase
S1 S3
S2
A
S4
B
After merging A and B
S1 S3
A
B
S2'
After rebasing B on A
Delete a Branch
• Delete a branch
– # git branch –d [name]
– Actually, this just deletes the branch pointer.
Ubiquitous Computing and Ambient Networking Laboratory Page : 12
Git Workflow
• Integration-Manager workflow
Ubiquitous Computing and Ambient Networking Laboratory Page : 13
Forked repositoryForked repository
Original repository
Integration
Manager
Forked repositories
Contributors
1. clone
2. create branch
3. make changes on branch
4. pull request
5. merge
Git Workflow (con't)
• Dictator and Lieutenants workflow
– Generally used by huge projects, such as Linux kernel
Ubiquitous Computing and Ambient Networking Laboratory Page : 14
Lieutenant
repositories
Lieutenant
repositoriesOriginal repository
Dictator
Lieutenant
repositories
Benevolent
dictators
1. clone
2. create branch
3. make changes on branches
4. pull request
5. merge
Lieutenant
repositories
Lieutenant
repositoriesForked repositories
Contributors
B. create branch
C. make changes on branches
D. rebase changes to master
A. clone
F. merge
E. pull request
GitHub Workflow
• GitHub is an example of Git workflow based on pull
request.
• In typical, GitHub workflow has the following steps
– Fork original project
– Create a topic branch on forked project
– Make changes on this topic branch
– Send a pull request to original project
– Discuss and make changes if necessary
– Owner of original project decides to merge or close this
pull request.
Ubiquitous Computing and Ambient Networking Laboratory Page : 15
Q & A
Ubiquitous Computing and Ambient Networking Laboratory Page : 16

More Related Content

PPT
Git basic
Emran Ul Hadi
 
PDF
Git Branching Model
Lemi Orhan Ergin
 
PPTX
A successful Git branching model
abodeltae
 
PPTX
Git - Basic Crash Course
Nilay Binjola
 
PPTX
Git in 10 minutes
Safique Ahmed Faruque
 
PPTX
Git vs svn
Rupesh Kumar
 
PDF
Starting with Git & GitHub
Nicolás Tourné
 
PDF
Git training v10
Skander Hamza
 
Git basic
Emran Ul Hadi
 
Git Branching Model
Lemi Orhan Ergin
 
A successful Git branching model
abodeltae
 
Git - Basic Crash Course
Nilay Binjola
 
Git in 10 minutes
Safique Ahmed Faruque
 
Git vs svn
Rupesh Kumar
 
Starting with Git & GitHub
Nicolás Tourné
 
Git training v10
Skander Hamza
 

What's hot (20)

PDF
Git basics
GHARSALLAH Mohamed
 
PPTX
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 
PPTX
Git & GitLab
Gaurav Wable
 
PPTX
GitHub Basics - Derek Bable
"FENG "GEORGE"" YU
 
PDF
Github - Git Training Slides: Foundations
Lee Hanxue
 
PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Git flow Introduction
David Paluy
 
PPTX
Introduction git
Dian Sigit Prastowo
 
PDF
Comparison of SVN and Git
Daniel Wieth
 
PDF
Git Branching for Agile Teams
Atlassian
 
PPTX
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Rueful Robin
 
ODP
Git vs svn
Suman Mukherjee
 
PDF
Git - An Introduction
Behzad Altaf
 
PPTX
Git basics to advance with diagrams
Dilum Navanjana
 
PPT
Introduction to Git and Github
Somkiat Puisungnoen
 
PPT
Git workflows presentation
Mack Hardy
 
PPTX
Intro to git and git hub
Venkat Malladi
 
PPTX
Introduction to git & GitHub
Poornachandrakashi
 
PDF
Git real slides
Lucas Couto
 
PPTX
Git commands
Viyaan Jhiingade
 
Git basics
GHARSALLAH Mohamed
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 
Git & GitLab
Gaurav Wable
 
GitHub Basics - Derek Bable
"FENG "GEORGE"" YU
 
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git and github 101
Senthilkumar Gopal
 
Git flow Introduction
David Paluy
 
Introduction git
Dian Sigit Prastowo
 
Comparison of SVN and Git
Daniel Wieth
 
Git Branching for Agile Teams
Atlassian
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Rueful Robin
 
Git vs svn
Suman Mukherjee
 
Git - An Introduction
Behzad Altaf
 
Git basics to advance with diagrams
Dilum Navanjana
 
Introduction to Git and Github
Somkiat Puisungnoen
 
Git workflows presentation
Mack Hardy
 
Intro to git and git hub
Venkat Malladi
 
Introduction to git & GitHub
Poornachandrakashi
 
Git real slides
Lucas Couto
 
Git commands
Viyaan Jhiingade
 
Ad

Similar to Git Branch (20)

PDF
Git cheat sheet
Piyush Mittal
 
PDF
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
 
PDF
Git Init (Introduction to Git)
GDSC UofT Mississauga
 
PPTX
Git basic stanley hsiao 2010_12_15
Chen-Han Hsiao
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPT
version_control_lectures_for _git_all.ppt
testbard37
 
PDF
Introduction to git, an efficient distributed version control system
AlbanLevy
 
PDF
git-presentation.pdf
2022bcacsbshubh12897
 
PPTX
Working with Git
Sanghoon Hong
 
PPTX
Git Repository for Developers working in Various Locations
Ganesh Bhosale
 
KEY
Use git the proper way
Jaime Buelta
 
PDF
Github
Sarah Eggleston
 
PDF
Professional Git 1st Edition Brent Laster
thomesaresia
 
PDF
Git, from the beginning
James Aylett
 
PPTX
MakingGitWorkForYou
Kwen Peterson
 
PDF
Did you git yet?
Michael Fong
 
PPTX
Jedi Mind Tricks for Git
Jan Krag
 
PPT
Report about the dangers of git and github on the environment
lameche1islam
 
PPT
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
PPT
Distributed Version control using Git and Github
RikinBasu1
 
Git cheat sheet
Piyush Mittal
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
 
Git Init (Introduction to Git)
GDSC UofT Mississauga
 
Git basic stanley hsiao 2010_12_15
Chen-Han Hsiao
 
Advanced Git Tutorial
Sage Sharp
 
version_control_lectures_for _git_all.ppt
testbard37
 
Introduction to git, an efficient distributed version control system
AlbanLevy
 
git-presentation.pdf
2022bcacsbshubh12897
 
Working with Git
Sanghoon Hong
 
Git Repository for Developers working in Various Locations
Ganesh Bhosale
 
Use git the proper way
Jaime Buelta
 
Professional Git 1st Edition Brent Laster
thomesaresia
 
Git, from the beginning
James Aylett
 
MakingGitWorkForYou
Kwen Peterson
 
Did you git yet?
Michael Fong
 
Jedi Mind Tricks for Git
Jan Krag
 
Report about the dangers of git and github on the environment
lameche1islam
 
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
Distributed Version control using Git and Github
RikinBasu1
 
Ad

More from Wei-Tsung Su (12)

PDF
軟體系統測試簡介
Wei-Tsung Su
 
PPTX
MQTT簡介與使用開放原始碼
Wei-Tsung Su
 
PPTX
LinkIt Smart 7688程式開發
Wei-Tsung Su
 
PDF
Arduino Yun Mini - 使用SQLite
Wei-Tsung Su
 
PDF
Arduino Yun Mini簡介
Wei-Tsung Su
 
PPTX
Google Glass - Unit01: Design
Wei-Tsung Su
 
PPTX
Google App Engine for Python - Unit01: Basic
Wei-Tsung Su
 
PPTX
Introduction to NFC
Wei-Tsung Su
 
PDF
創業的藝術
Wei-Tsung Su
 
PDF
Introduction to Version Control
Wei-Tsung Su
 
PDF
Introduction to Wi-Fi Direct
Wei-Tsung Su
 
PDF
Introduction to OAuth
Wei-Tsung Su
 
軟體系統測試簡介
Wei-Tsung Su
 
MQTT簡介與使用開放原始碼
Wei-Tsung Su
 
LinkIt Smart 7688程式開發
Wei-Tsung Su
 
Arduino Yun Mini - 使用SQLite
Wei-Tsung Su
 
Arduino Yun Mini簡介
Wei-Tsung Su
 
Google Glass - Unit01: Design
Wei-Tsung Su
 
Google App Engine for Python - Unit01: Basic
Wei-Tsung Su
 
Introduction to NFC
Wei-Tsung Su
 
創業的藝術
Wei-Tsung Su
 
Introduction to Version Control
Wei-Tsung Su
 
Introduction to Wi-Fi Direct
Wei-Tsung Su
 
Introduction to OAuth
Wei-Tsung Su
 

Recently uploaded (20)

PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
Information Retrieval and Extraction - Module 7
premSankar19
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 

Git Branch

  • 1. Git Branch Wei-Tsung Su (蘇維宗) [email protected] 11/23/2017 (Ver. 1.0) Ubiquitous Computing and Ambient Networking Laboratory Page : 1
  • 2. Change Log Date Ver. Authors Description 11/23/2017 V1.0 Wei-Tsung Su Baseline Ubiquitous Computing and Ambient Networking Laboratory 2
  • 3. Reference • Scott Chacon, Git Pro, Jul. 29, 2009. Available: http://git-scm.com/book Ubiquitous Computing and Ambient Networking Laboratory Page : 3
  • 4. Agenda • What is branch? • Why using branch? • Operations – Create and checkout a branch – Merge two branches – Remove conflicts – Rebase branch on the other one – Delete a branch • Git Workflow • GitHub Workflow • Demonstration Ubiquitous Computing and Ambient Networking Laboratory Page : 4
  • 5. What is branch? • Branching model is referred as a killer feature of Git. • Git commit data structure – Point master is a branch pointing to a specific snapshot. – Point HEAD is pointing to current working branch. Ubiquitous Computing and Ambient Networking Laboratory Page : 5 commit tree Snapshot A blob File 3 blob File 2 blob File 1 commit tree Snapshot B commit tree Snapshot C master HEAD blob File 1 (modified) Compressed
  • 6. Why using branch? • Case 1 – Issue fixing without polluting stable version. – Merge is required after issue has been fixed. • Case 2 – Creating different product lines for various platforms, customers, etc. – Merge may or may not be required. • Others Ubiquitous Computing and Ambient Networking Laboratory Page : 6
  • 7. Create and checkout a Branch • Create a new branch – git branch [name] • Checkout a branch (move HEAD to a branch) – git checkout [name] • Create and checkout a new branch – git checkout –b [name] Ubiquitous Computing and Ambient Networking Laboratory Page : 7
  • 8. Merge two branches • Assume merge branch B into branch A – # git checkout A – # git merge B • However, there may be conflicts while merging two branches. That is, the same part of the file is changed differently in two branches. Ubiquitous Computing and Ambient Networking Laboratory Page : 8
  • 9. Remove Conflict • Step 1. check the files which have conflicts <<<<<<< HEAD:index.html <div id="footer">contact : [email protected]</div> ======= <div id="footer"> please contact us at [email protected] </div> >>>>>>> iss53:index.html • Step 2. remove conflicts manually • Step 3. commit changes – # git commit Ubiquitous Computing and Ambient Networking Laboratory Page : 9
  • 10. Rebase branch on the other one • Assume rebase branch B on branch A – # git checkout B – # git rebase A • Similarly, remove conflicts if rebasing a branch on the other one. – Abort rebasing • # git rebase --abort – Continue rebasing – # git add . – # git rebase --continue – # git checkout A – # git merge B • Note – DO NOT rebase the commits that are pushed to public repository. Ubiquitous Computing and Ambient Networking Laboratory Page : 10
  • 11. Merge v.s. Rebase Ubiquitous Computing and Ambient Networking Laboratory Page : 11 S1 S3 S2 A B Before merge or rebase S1 S3 S2 A S4 B After merging A and B S1 S3 A B S2' After rebasing B on A
  • 12. Delete a Branch • Delete a branch – # git branch –d [name] – Actually, this just deletes the branch pointer. Ubiquitous Computing and Ambient Networking Laboratory Page : 12
  • 13. Git Workflow • Integration-Manager workflow Ubiquitous Computing and Ambient Networking Laboratory Page : 13 Forked repositoryForked repository Original repository Integration Manager Forked repositories Contributors 1. clone 2. create branch 3. make changes on branch 4. pull request 5. merge
  • 14. Git Workflow (con't) • Dictator and Lieutenants workflow – Generally used by huge projects, such as Linux kernel Ubiquitous Computing and Ambient Networking Laboratory Page : 14 Lieutenant repositories Lieutenant repositoriesOriginal repository Dictator Lieutenant repositories Benevolent dictators 1. clone 2. create branch 3. make changes on branches 4. pull request 5. merge Lieutenant repositories Lieutenant repositoriesForked repositories Contributors B. create branch C. make changes on branches D. rebase changes to master A. clone F. merge E. pull request
  • 15. GitHub Workflow • GitHub is an example of Git workflow based on pull request. • In typical, GitHub workflow has the following steps – Fork original project – Create a topic branch on forked project – Make changes on this topic branch – Send a pull request to original project – Discuss and make changes if necessary – Owner of original project decides to merge or close this pull request. Ubiquitous Computing and Ambient Networking Laboratory Page : 15
  • 16. Q & A Ubiquitous Computing and Ambient Networking Laboratory Page : 16