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

PDF
Git Branching Model
PPT
Git basic
PPT
Git workflows presentation
PDF
Git flow Introduction
PPTX
Git branching strategies
PPTX
Git and GitFlow branching model
PPTX
Git - Basic Crash Course
PDF
Dealing with Merge Conflicts in Git
Git Branching Model
Git basic
Git workflows presentation
Git flow Introduction
Git branching strategies
Git and GitFlow branching model
Git - Basic Crash Course
Dealing with Merge Conflicts in Git

What's hot (20)

PDF
Introduction to git flow
PPTX
Git 101 for Beginners
PDF
Learning git
PPTX
BitBucket presentation
PPTX
A successful Git branching model
PDF
Git for beginners
PDF
Git and Github slides.pdf
PDF
Git basics
PDF
Git Version Control System
PDF
Git flow
PPTX
Git commands
PDF
PDF
Introducing GitLab (June 2018)
PDF
Github - Git Training Slides: Foundations
PPTX
Git Branching and Merging.pptx
PDF
Git branch management
PPTX
PDF
Git and github 101
PDF
Git - An Introduction
KEY
The everyday developer's guide to version control with Git
Introduction to git flow
Git 101 for Beginners
Learning git
BitBucket presentation
A successful Git branching model
Git for beginners
Git and Github slides.pdf
Git basics
Git Version Control System
Git flow
Git commands
Introducing GitLab (June 2018)
Github - Git Training Slides: Foundations
Git Branching and Merging.pptx
Git branch management
Git and github 101
Git - An Introduction
The everyday developer's guide to version control with Git
Ad

Similar to Git Branch (20)

PPTX
Introduction to git, a version control system
PPTX
Git Repository for Developers working in Various Locations
PPTX
Real-World Git
PPTX
Working with Git
PDF
The Basics of Open Source Collaboration With Git and GitHub
PDF
[PUBLIC] Git – Concepts and Workflows.pdf
PDF
Introduction to git, an efficient distributed version control system
ZIP
Beginner's Guide to Version Control with Git
PPT
PPTX
Introduce to Git and Jenkins
PPTX
Git tutorial git branches 20131206-Bryan
PPTX
Git more done
PDF
Git workflows automat-it
PPTX
Intro to git and git hub
PDF
Collaborative development with Git | Workshop
PPTX
Git Basics for Software Version Management
PDF
Git tutorial
PDF
Git interview questions | Edureka
PPT
Talk to git
PDF
Switching to Git
Introduction to git, a version control system
Git Repository for Developers working in Various Locations
Real-World Git
Working with Git
The Basics of Open Source Collaboration With Git and GitHub
[PUBLIC] Git – Concepts and Workflows.pdf
Introduction to git, an efficient distributed version control system
Beginner's Guide to Version Control with Git
Introduce to Git and Jenkins
Git tutorial git branches 20131206-Bryan
Git more done
Git workflows automat-it
Intro to git and git hub
Collaborative development with Git | Workshop
Git Basics for Software Version Management
Git tutorial
Git interview questions | Edureka
Talk to git
Switching to Git
Ad

More from Wei-Tsung Su (12)

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

Recently uploaded (20)

PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
737-MAX_SRG.pdf student reference guides
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
PPT on Performance Review to get promotions
PPT
Occupational Health and Safety Management System
PPT
introduction to datamining and warehousing
PPTX
UNIT - 3 Total quality Management .pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
communication and presentation skills 01
PPTX
Current and future trends in Computer Vision.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
86236642-Electric-Loco-Shed.pdf jfkduklg
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
737-MAX_SRG.pdf student reference guides
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT on Performance Review to get promotions
Occupational Health and Safety Management System
introduction to datamining and warehousing
UNIT - 3 Total quality Management .pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
communication and presentation skills 01
Current and future trends in Computer Vision.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Fundamentals of safety and accident prevention -final (1).pptx
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...

Git Branch

  • 1. Git Branch Wei-Tsung Su (蘇維宗) ellington.su@gmail.com 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.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
  • 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