SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Git Tutorial – Git Branches
Bryan Lin
2013/12/06
Agenda
Overview
git branch
git checkout
git merge
Overview
Creating branches
How git checkout can be used to select a branch
How git merge can integrate the history of independent
branches
git branch
A branch represents an independent line of development
The git branch command lets you create, list, rename, and
delete branches
git branch
Usage
git branch
• List all of the branches in your repository

git branch <branch>
• Create a new branch called <branch>
• This does not check out the new branch

git branch -d <branch>
• Delete the specified branch
• This is a “safe” operation in that Git prevents you from deleting the branch
if it has unmerged changes
git branch
Usage
git branch -D <branch>
• Force delete the specified branch, even if it has unmerged changes. This is
the command to use if you want to permanently throw away all of the
commits associated with a particular line of development

git branch -m <branch>
• Rename the current branch to <branch>
git branch
Discussion
In Git, branches are a part of your everyday development process.
When you want to add a new feature or fix a bug—no matter how
big or how small—you spawn a new branch to encapsulate your
changes. This makes sure that unstable code is never committed to
the main code base, and it gives you the chance to clean up your
feature’s history before merging it into the main branch.
git branch
Discussion
For example, the diagram below visualizes a repository with two
isolated lines of development, one for a little feature, and one for a
longer-running feature. By developing them in branches, it’s not
only possible to work on both of them in parallel, but it also keeps
the main master branch free from questionable code.
git branch
Discussion
Branch Tips
• The implementation behind Git branches is much more lightweight than
SVN’s model. Instead of copying files from directory to directory, Git
stores a branch as a reference to a commit. In this sense, a branch
represents the tip of a series of commits—it's not a container for commits.
The history for a branch is extrapolated through the commit relationships.
• This has a dramatic impact on Git's merging model. Whereas merges in
SVN are done on a file-basis, Git lets you work on the more abstract level
of commits. You can actually see merges in the project history as a joining
of two independent commit histories.
git branch
Discussion
Branch Tips
• The implementation behind Git branches is much more lightweight than
SVN’s model. Instead of copying files from directory to directory, Git
stores a branch as a reference to a commit. In this sense, a branch
represents the tip of a series of commits—it's not a container for commits.
The history for a branch is extrapolated through the commit relationships.
• This has a dramatic impact on Git's merging model. Whereas merges in
SVN are done on a file-basis, Git lets you work on the more abstract level
of commits. You can actually see merges in the project history as a joining
of two independent commit histories.
git checkout
The git checkout command lets you navigate between the
branches created by git branch
Checking out a branch updates the files in the working
directory to match the version stored in that branch, and it
tells Git to record all new commits on that branch. Think of it
as a way to select which line of development you’re working
on.
git checkout
Usage
git checkout <existing-branch>
• Check out the specified branch, which should have already been created
with git branch. This makes <existing-branch> the current branch, and
updates the working directory to match.

git checkout -b <new-branch>
• Create and check out <new-branch>. The -b option is a convenience flag
that tells Git to run git branch <new-branch> before running git checkout
<new-branch>.
git checkout
Usage
git checkout -b <new-branch> <existing-branch>
• Same as the above invocation, but base the new branch off of <existingbranch> instead of the current branch.
git checkout
Discussion
git checkout works hand-in-hand with git branch. When you want
to start a new feature, you create a branch with git branch, then
check it out with git checkout. You can work on multiple features
in a single repository by switching between them with git checkout.
git checkout
Discussion
git checkout
Discussion
Having a dedicated branch for each new feature is a dramatic shift
from the traditional SVN workflow. It makes it ridiculously easy to
try new experiments without the fear of destroying existing
functionality, and it makes it possible to work on many unrelated
features at the same time. In addition, branches also facilitate
several collaborative workflows.
git checkout
Discussion
Detached HEADs
• The git checkout command simply updates the HEAD to point to either the
specified branch or commit. When it points to a branch, Git doesn't
complain, but when you check out a commit, it switches into a
“detached HEAD” state.
git checkout
Discussion
Detached HEADs
• If you were to start developing a feature while in a detached HEAD state,
there would be no branch allowing you to get back to it. When you
inevitably check out another branch (e.g., to merge your feature in), there
would be no way to reference your feature:
git merge
Merging is Git's way of putting a forked history back
together again.
The git merge command lets you take the independent lines
of development created by git branch and integrate them into
a single branch.
git merge
Usage
git merge <branch>
• Merge the specified branch into the current branch. Git will determine the
merge algorithm automatically

git merge --no-ff <branch>
• Merge the specified branch into the current branch, but always generate a
merge commit (even if it was a fast-forward merge). This is useful for
documenting all merges that occur in your repository.
git merge
Discussion
Git has several distinct algorithms to accomplish this: a fastforward merge or a 3-way merge.
A fast-forward merge can occur when there is a linear path from
the current branch tip to the target branch. Instead of “actually”
merging the branches, all Git has to do to integrate the histories is
move (i.e., “fast forward”) the current branch tip up to the target
branch tip.
git merge
Discussion
For example, a fast forward merge of somefeature into master would look something like the following:
git merge
Discussion
A fast-forward merge is not possible if the branches have diverged.
When there is not a linear path to the target branch, Git has no
choice but to combine them via a 3-way merge
3-way merges use a dedicated commit to tie together the two
histories. The nomenclature comes from the fact that Git uses
three commits to generate the merge commit: the two branch tips
and their common ancestor.
git merge
Discussion
git merge
Discussion
Resolving Conflicts
• If the two branches you're trying to merge both changed the same part of
the same file, Git won't be able to figure out which version to use. When
such a situation occurs, it stops right before the merge commit so that you
can resolve the conflicts manually.
• The great part of Git's merging process is that it uses the familiar
edit/stage/commit workflow to resolve merge conflicts. When you
encounter a merge conflict, running the git status command shows you
which files need to be resolved.
git merge
Discussion
Resolving Conflicts
• For example, if both branches modified the same section of hello.py, you
would see something like the following:
git merge
Discussion
Resolving Conflicts
• When you're ready to finish the merge, all you have to do is run git add on
the conflicted file(s) to tell Git they're resolved. Then, you run a normal git
commit to generate the merge commit.
FAQ

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshareRakesh Sukumar
 
Git for folk who like GUIs
Git for folk who like GUIsGit for folk who like GUIs
Git for folk who like GUIsTim Osborn
 
Git with bitbucket
Git with bitbucketGit with bitbucket
Git with bitbucketSumin Byeon
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHubDSCVSSUT
 
Git Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowGit Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowMikhail Melnik
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02Gourav Varma
 
Gitt and Git-flow
Gitt and Git-flowGitt and Git-flow
Gitt and Git-flowMd. Masud
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01Gourav Varma
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentalsRajKharvar
 

Was ist angesagt? (20)

Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 
Git presentation
Git presentationGit presentation
Git presentation
 
BitBucket presentation
BitBucket presentationBitBucket presentation
BitBucket presentation
 
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshare
 
Git for folk who like GUIs
Git for folk who like GUIsGit for folk who like GUIs
Git for folk who like GUIs
 
Git with bitbucket
Git with bitbucketGit with bitbucket
Git with bitbucket
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Git Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowGit Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-Flow
 
Git
GitGit
Git
 
Git learning
Git learningGit learning
Git learning
 
Git Pull Requests
Git Pull RequestsGit Pull Requests
Git Pull Requests
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Intro to Gitflow
Intro to GitflowIntro to Gitflow
Intro to Gitflow
 
Git with bitbucket
Git with bitbucketGit with bitbucket
Git with bitbucket
 
Gitt and Git-flow
Gitt and Git-flowGitt and Git-flow
Gitt and Git-flow
 
Bitbucket and Git
Bitbucket and GitBitbucket and Git
Bitbucket and Git
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
 
Git and github fundamentals
Git and github fundamentalsGit and github fundamentals
Git and github fundamentals
 

Andere mochten auch

Andere mochten auch (10)

Branch model in Git
Branch model in GitBranch model in Git
Branch model in Git
 
Git basic
Git basicGit basic
Git basic
 
sahithi_Build_Release_Resume
sahithi_Build_Release_Resumesahithi_Build_Release_Resume
sahithi_Build_Release_Resume
 
Nitin resume dev_ops
Nitin resume dev_opsNitin resume dev_ops
Nitin resume dev_ops
 
Release build engineer j2ee focused
Release build engineer   j2ee focusedRelease build engineer   j2ee focused
Release build engineer j2ee focused
 
Santhosh build and release (1)
Santhosh build and release (1)Santhosh build and release (1)
Santhosh build and release (1)
 
Khaleel Devops Resume (2)
Khaleel Devops Resume (2)Khaleel Devops Resume (2)
Khaleel Devops Resume (2)
 
Dev ops engineer
Dev ops engineerDev ops engineer
Dev ops engineer
 
Vighnesh_Naik_Resume_DevOps
Vighnesh_Naik_Resume_DevOpsVighnesh_Naik_Resume_DevOps
Vighnesh_Naik_Resume_DevOps
 
Git vol 2
Git vol 2Git vol 2
Git vol 2
 

Ähnlich wie Git tutorial git branches 20131206-Bryan

Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideRaghavendraVattikuti1
 
Git Branching and Merging.pptx
Git Branching and Merging.pptxGit Branching and Merging.pptx
Git Branching and Merging.pptxtapanvyas11
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperJohn Stevenson
 
Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow Sebin Benjamin
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptxEshaan35
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nadaLama K Banna
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answersDeepQuest Software
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)Yeasin Abedin
 
Git basics a starter on git and its ecosystem
Git basics  a starter on git and its ecosystemGit basics  a starter on git and its ecosystem
Git basics a starter on git and its ecosystemFrançois D'Agostini
 

Ähnlich wie Git tutorial git branches 20131206-Bryan (20)

Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
Git slides
Git slidesGit slides
Git slides
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Git Branching and Merging.pptx
Git Branching and Merging.pptxGit Branching and Merging.pptx
Git Branching and Merging.pptx
 
Introduction to Git (part 2)
Introduction to Git (part 2)Introduction to Git (part 2)
Introduction to Git (part 2)
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Git tips
Git tipsGit tips
Git tips
 
GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Git hub abduallah abu nada
Git hub   abduallah abu nadaGit hub   abduallah abu nada
Git hub abduallah abu nada
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answers
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)
 
Git basics a starter on git and its ecosystem
Git basics  a starter on git and its ecosystemGit basics  a starter on git and its ecosystem
Git basics a starter on git and its ecosystem
 

Mehr von LearningTech

Mehr von LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Kürzlich hochgeladen

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

Git tutorial git branches 20131206-Bryan

  • 1. Git Tutorial – Git Branches Bryan Lin 2013/12/06
  • 3. Overview Creating branches How git checkout can be used to select a branch How git merge can integrate the history of independent branches
  • 4. git branch A branch represents an independent line of development The git branch command lets you create, list, rename, and delete branches
  • 5. git branch Usage git branch • List all of the branches in your repository git branch <branch> • Create a new branch called <branch> • This does not check out the new branch git branch -d <branch> • Delete the specified branch • This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes
  • 6. git branch Usage git branch -D <branch> • Force delete the specified branch, even if it has unmerged changes. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development git branch -m <branch> • Rename the current branch to <branch>
  • 7. git branch Discussion In Git, branches are a part of your everyday development process. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. This makes sure that unstable code is never committed to the main code base, and it gives you the chance to clean up your feature’s history before merging it into the main branch.
  • 8. git branch Discussion For example, the diagram below visualizes a repository with two isolated lines of development, one for a little feature, and one for a longer-running feature. By developing them in branches, it’s not only possible to work on both of them in parallel, but it also keeps the main master branch free from questionable code.
  • 9. git branch Discussion Branch Tips • The implementation behind Git branches is much more lightweight than SVN’s model. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit. In this sense, a branch represents the tip of a series of commits—it's not a container for commits. The history for a branch is extrapolated through the commit relationships. • This has a dramatic impact on Git's merging model. Whereas merges in SVN are done on a file-basis, Git lets you work on the more abstract level of commits. You can actually see merges in the project history as a joining of two independent commit histories.
  • 10. git branch Discussion Branch Tips • The implementation behind Git branches is much more lightweight than SVN’s model. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit. In this sense, a branch represents the tip of a series of commits—it's not a container for commits. The history for a branch is extrapolated through the commit relationships. • This has a dramatic impact on Git's merging model. Whereas merges in SVN are done on a file-basis, Git lets you work on the more abstract level of commits. You can actually see merges in the project history as a joining of two independent commit histories.
  • 11. git checkout The git checkout command lets you navigate between the branches created by git branch Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. Think of it as a way to select which line of development you’re working on.
  • 12. git checkout Usage git checkout <existing-branch> • Check out the specified branch, which should have already been created with git branch. This makes <existing-branch> the current branch, and updates the working directory to match. git checkout -b <new-branch> • Create and check out <new-branch>. The -b option is a convenience flag that tells Git to run git branch <new-branch> before running git checkout <new-branch>.
  • 13. git checkout Usage git checkout -b <new-branch> <existing-branch> • Same as the above invocation, but base the new branch off of <existingbranch> instead of the current branch.
  • 14. git checkout Discussion git checkout works hand-in-hand with git branch. When you want to start a new feature, you create a branch with git branch, then check it out with git checkout. You can work on multiple features in a single repository by switching between them with git checkout.
  • 16. git checkout Discussion Having a dedicated branch for each new feature is a dramatic shift from the traditional SVN workflow. It makes it ridiculously easy to try new experiments without the fear of destroying existing functionality, and it makes it possible to work on many unrelated features at the same time. In addition, branches also facilitate several collaborative workflows.
  • 17. git checkout Discussion Detached HEADs • The git checkout command simply updates the HEAD to point to either the specified branch or commit. When it points to a branch, Git doesn't complain, but when you check out a commit, it switches into a “detached HEAD” state.
  • 18. git checkout Discussion Detached HEADs • If you were to start developing a feature while in a detached HEAD state, there would be no branch allowing you to get back to it. When you inevitably check out another branch (e.g., to merge your feature in), there would be no way to reference your feature:
  • 19. git merge Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
  • 20. git merge Usage git merge <branch> • Merge the specified branch into the current branch. Git will determine the merge algorithm automatically git merge --no-ff <branch> • Merge the specified branch into the current branch, but always generate a merge commit (even if it was a fast-forward merge). This is useful for documenting all merges that occur in your repository.
  • 21. git merge Discussion Git has several distinct algorithms to accomplish this: a fastforward merge or a 3-way merge. A fast-forward merge can occur when there is a linear path from the current branch tip to the target branch. Instead of “actually” merging the branches, all Git has to do to integrate the histories is move (i.e., “fast forward”) the current branch tip up to the target branch tip.
  • 22. git merge Discussion For example, a fast forward merge of somefeature into master would look something like the following:
  • 23. git merge Discussion A fast-forward merge is not possible if the branches have diverged. When there is not a linear path to the target branch, Git has no choice but to combine them via a 3-way merge 3-way merges use a dedicated commit to tie together the two histories. The nomenclature comes from the fact that Git uses three commits to generate the merge commit: the two branch tips and their common ancestor.
  • 25. git merge Discussion Resolving Conflicts • If the two branches you're trying to merge both changed the same part of the same file, Git won't be able to figure out which version to use. When such a situation occurs, it stops right before the merge commit so that you can resolve the conflicts manually. • The great part of Git's merging process is that it uses the familiar edit/stage/commit workflow to resolve merge conflicts. When you encounter a merge conflict, running the git status command shows you which files need to be resolved.
  • 26. git merge Discussion Resolving Conflicts • For example, if both branches modified the same section of hello.py, you would see something like the following:
  • 27. git merge Discussion Resolving Conflicts • When you're ready to finish the merge, all you have to do is run git add on the conflicted file(s) to tell Git they're resolved. Then, you run a normal git commit to generate the merge commit.
  • 28. FAQ