SlideShare a Scribd company logo
1 of 33
Git and Git-Ops
Lecture 3
Git Branching and Merging
Install Git On Windows
Configuration of Git
Creating a Git Repository and
Connecting it to a Remote Repository
By the end of the session, we will be able to:
▪ Comprehend the concept and importance of branching
in Git.
▪ Acquire proficiency in creating, switching between,
listing.
▪ Master the process of merging branches.
▪ Develop essential skills in resolving merge conflicts.
Session Objectives
Branching in Git
Merging Branches in Git
Resolving Conflicts
Branching in Git
● In Git, branching is a powerful feature that enables
developers to create separate lines of
development within a repository.
● It provides a flexible and efficient way to work on
multiple features, bug fixes, or experiments
simultaneously without interference.
● By understanding and harnessing the concept of
branching, developers can enhance collaboration,
streamline workflows, and maintain a well-
structured codebase.
Branching in Git
● The concept of branching revolves around the idea
of creating a divergent path from the main line of
development.
● It allows developers to isolate their work, make
changes, and iterate on specific tasks without
impacting the stability of the main codebase.
● Each branch in Git represents an independent line
of development, enabling developers to work in
parallel on different features or address separate
issues.
Branching in Git
Creating a Branch:
● Creating a new branch in Git is a simple and
straightforward process. By using the git branch
command followed by the desired branch name,
developers can create a new branch based on their
current position.
● To create a new branch in Git, use the following
command:
git branch <branch_name>
● Replace <branch_name> with the desired name for
your new branch.
Branching in Git
Creating a Branch:
● This new branch starts with the same commit
history as the branch it was created from, ensuring
that all existing work is inherited. This way,
developers can build upon the existing codebase
without disrupting the progress made on other
branches. For example:
git branch feature-branch
● This command creates a new branch named
"feature-branch" based on your current branch. It
does not switch to the new branch; it simply
creates it.
Branching in Git
Switching to a Branch:
● Switching between branches is another essential
aspect of branching in Git. By using the git
checkout command followed by the branch name,
developers can seamlessly transition to a different
branch and continue their work in that context.
● Switching between branches updates the working
directory to reflect the state of the selected
branch, allowing developers to access the specific
set of code and files associated with that branch.
Branching in Git
Switching to a Branch:
● To switch to a different branch, use the following
command:
git checkout <branch_name>
● Replace <branch_name> with the name of the branch
you want to switch to.For example-
git checkout feature-branch
● This command switches you to the "feature-branch"
and updates your working directory to reflect the
state of that branch. Now, any changes you make will
be isolated to the "feature-branch" without affecting
the main branch or any other branches.
Branching in Git
Listing Branches:
● To view all branches in your repository, use the
following command:
git branch
● This command will display a list of local branches,
with an asterisk (*) indicating the currently active
branch.
Branching in Git
Deleting a Branch:
● When a branch has served its purpose or is no longer
needed, you can delete it using the git branch -d
command followed by the branch name. However,
note that you cannot delete the branch you are
currently on. First, switch to a different branch and
then delete the branch you wish to remove.
● To delete a branch, use the following command:
git branch -d <branch_name>
● Replace <branch_name> with the name of the
branch you want to delete.For example-
git branch -d feature-branch
● This command will delete the "feature-branch" from
your repository.
Branching in Git
Merging Branches in Git
Resolving Conflicts
Merging Branches in Git
● Merging is a fundamental process in Git that
enables you to combine changes from one branch
into another.
● It plays a crucial role in integrating new features,
bug fixes, or improvements into the main branch or
any target branch.
● This part of the chapter will delve into the
intricacies of merging branches in Git, ensuring a
smooth and efficient integration of changes.
● Merging branches in Git involves bringing the
changes made in one branch into another branch.
Merging Branches in Git
● This process consolidates the work done in
different branches, allowing developers to
synchronize their efforts and ensure that all
relevant updates are incorporated into the final
codebase.
● By merging branches, you can take advantage of
parallel development, enabling different team
members to work on separate features
simultaneously.
● Git provides various strategies for merging
branches, depending on the complexity and
context of the changes.
Types of Merges
Fast-forward merges Automatic commit merges
Merging Branches in Git
Fast-forward Merge:
● A fast-forward merge is performed when the
branch you want to merge has a linear commit
history and there are no new commits in the target
branch since the divergence.
● In this case, the target branch simply moves
forward to include the new commits from the
source branch. This results in a linear commit
history, with all changes seamlessly integrated.
Merging Branches in Git
Fast-forward Merge:
● To perform a fast-forward merge, follow these
steps:
● Switch to the target branch:
git checkout <target_branch>
● Merge the source branch into the target branch:
git merge <source_branch>
● Replace <target_branch> with the branch you want
to merge into, and <source_branch> with the
branch containing the new commits.
Merging Branches in Git
Fast-forward Merge:
● For example, let's say you have a feature branch
named "feature-branch" and you want to merge it
into the main branch. The following commands
would accomplish this:
git checkout main
git merge feature-branch
Merging Branches in Git
Automatic Commit Merge:
● An automatic commit merge is performed when
both the target and source branches have new
commits since they diverged.
● Git creates a new commit that combines the
changes from both branches, ensuring that all
modifications are incorporated while maintaining a
clear history of the individual branches.
Merging Branches in Git
Automatic Commit Merge:
● To initiate an automatic commit merge, use the
following commands:
● Switch to the target branch:
git checkout <target_branch>
● Merge the source branch into the target branch:
git merge <source_branch>
● During an automatic commit merge, Git opens a text
editor where you can enter a merge commit message.
This message should provide a concise summary of
the changes being merged.
Merging Branches in Git
Automatic Commit Merge:
● For example, if you want to merge a feature branch
named "feature-branch" into the main branch, you
would run the following commands:
git checkout main
git merge feature-branch
Branching in Git
Merging Branches in Git
Resolving Conflicts
Merge conflicts occur when Git encounters conflicting changes in
different branches during a merge operation. Resolving these conflicts
is an essential skill that every developer should master.
Merge conflicts
Resolving Merge Conflicts
Identifying Conflicts:
● When a merge conflict occurs, Git modifies the
affected files and marks the conflicting lines with
conflict markers. These conflict markers help you
identify the conflicting changes.
Resolving Merge Conflicts
Identifying Conflicts:
● Typically, Git uses the following markers:
<<<<<<< HEAD
... Changes from the current branch ...
=======
... Changes from the incoming branch ...
>>>>>>> incoming_branch
● The portion between <<<<<<< HEAD and =======
represents the changes made in the current branch,
while the portion between ======= and >>>>>>>
incoming_branch represents the changes made in
the incoming branch.
Resolving Conflicts:
● To resolve merge conflicts, follow these steps:
● Manually edit the conflicting files: Open the
conflicting files in a text editor and locate the
conflict markers. Review the conflicting changes and
determine the desired outcome.
● Remove conflict markers: Remove the conflict
markers and decide which changes to keep. You can
choose the changes from either the current branch or
the incoming branch, or modify the content to create
a new version that combines both sets of changes.
● Save the changes: After resolving the conflicts, save
the modified files.
Resolving Conflicts:
● Committing the Merge: Once you have resolved all the
conflicts, you need to stage the updated files and
create a merge commit to finalize the merge
operation.
● Add updated files to the staging area: Use the git add
command to add the modified files to the staging
area. This marks the resolved conflicts as ready to be
committed.
git add <file1> <file2> ...
Resolving Conflicts:
● Create a merge commit: Use the git commit
command to create a merge commit that
incorporates the resolved conflicts and completes
the merge operation. Provide a meaningful commit
message that describes the changes made during
the merge.
git commit
● By following these steps, you can effectively
resolve merge conflicts in Git, ensuring that
conflicting changes are harmoniously integrated
into the codebase.
Branching in Git
Merging Branches in Git
Resolving Conflicts
Lecture 3 Activity 1
Time for an activity.
Lecture 3 Activity 2
Time for an activity.
Git Branching and Merging.pptx

More Related Content

Similar to Git Branching and Merging.pptx

Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
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
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflowsArthur Shvetsov
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answersDeepQuest Software
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for developmentGerrit Wanderer
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control systemKumaresh Chandra Baruri
 
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...msohn
 
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a feature
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a featureGit Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a feature
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a featuremsohn
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate CourseAli Abbasi
 
Introduction to git flow
Introduction to git flowIntroduction to git flow
Introduction to git flowKnoldus Inc.
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__greyKing Hom
 
Git cheat sheet__white
Git cheat sheet__whiteGit cheat sheet__white
Git cheat sheet__whiteKing Hom
 
Git cheat sheet_dark
Git cheat sheet_darkGit cheat sheet_dark
Git cheat sheet_darkKing Hom
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptxEshaan35
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02Gourav Varma
 

Similar to Git Branching and Merging.pptx (20)

GIT Rebasing and Merging
GIT Rebasing and MergingGIT Rebasing and Merging
GIT Rebasing and Merging
 
Git for developers
Git for developersGit for developers
Git for developers
 
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
 
Formation git
Formation gitFormation git
Formation git
 
Git and GitHub workflows
Git and GitHub workflowsGit and GitHub workflows
Git and GitHub workflows
 
Gn unify git
Gn unify gitGn unify git
Gn unify git
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answers
 
Checkitmobile - using Git for development
Checkitmobile - using Git for developmentCheckitmobile - using Git for development
Checkitmobile - using Git for development
 
GDSC Git event 2023.pptx
GDSC Git event 2023.pptxGDSC Git event 2023.pptx
GDSC Git event 2023.pptx
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
Git Tutorial EclipseCon France 2014 - Git Exercise 03 - work on branches in p...
 
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a feature
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a featureGit Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a feature
Git Tutorial EclipseCon France 2014 - Git Exercise 02 - develop a feature
 
Git Best Practices.pptx
Git Best Practices.pptxGit Best Practices.pptx
Git Best Practices.pptx
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate Course
 
Introduction to git flow
Introduction to git flowIntroduction to git flow
Introduction to git flow
 
Git cheat sheet__grey
Git cheat sheet__greyGit cheat sheet__grey
Git cheat sheet__grey
 
Git cheat sheet__white
Git cheat sheet__whiteGit cheat sheet__white
Git cheat sheet__white
 
Git cheat sheet_dark
Git cheat sheet_darkGit cheat sheet_dark
Git cheat sheet_dark
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 

Recently uploaded

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 

Recently uploaded (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 

Git Branching and Merging.pptx

  • 1. Git and Git-Ops Lecture 3 Git Branching and Merging
  • 2. Install Git On Windows Configuration of Git Creating a Git Repository and Connecting it to a Remote Repository
  • 3. By the end of the session, we will be able to: ▪ Comprehend the concept and importance of branching in Git. ▪ Acquire proficiency in creating, switching between, listing. ▪ Master the process of merging branches. ▪ Develop essential skills in resolving merge conflicts. Session Objectives
  • 4. Branching in Git Merging Branches in Git Resolving Conflicts
  • 5. Branching in Git ● In Git, branching is a powerful feature that enables developers to create separate lines of development within a repository. ● It provides a flexible and efficient way to work on multiple features, bug fixes, or experiments simultaneously without interference. ● By understanding and harnessing the concept of branching, developers can enhance collaboration, streamline workflows, and maintain a well- structured codebase.
  • 6. Branching in Git ● The concept of branching revolves around the idea of creating a divergent path from the main line of development. ● It allows developers to isolate their work, make changes, and iterate on specific tasks without impacting the stability of the main codebase. ● Each branch in Git represents an independent line of development, enabling developers to work in parallel on different features or address separate issues.
  • 7. Branching in Git Creating a Branch: ● Creating a new branch in Git is a simple and straightforward process. By using the git branch command followed by the desired branch name, developers can create a new branch based on their current position. ● To create a new branch in Git, use the following command: git branch <branch_name> ● Replace <branch_name> with the desired name for your new branch.
  • 8. Branching in Git Creating a Branch: ● This new branch starts with the same commit history as the branch it was created from, ensuring that all existing work is inherited. This way, developers can build upon the existing codebase without disrupting the progress made on other branches. For example: git branch feature-branch ● This command creates a new branch named "feature-branch" based on your current branch. It does not switch to the new branch; it simply creates it.
  • 9. Branching in Git Switching to a Branch: ● Switching between branches is another essential aspect of branching in Git. By using the git checkout command followed by the branch name, developers can seamlessly transition to a different branch and continue their work in that context. ● Switching between branches updates the working directory to reflect the state of the selected branch, allowing developers to access the specific set of code and files associated with that branch.
  • 10. Branching in Git Switching to a Branch: ● To switch to a different branch, use the following command: git checkout <branch_name> ● Replace <branch_name> with the name of the branch you want to switch to.For example- git checkout feature-branch ● This command switches you to the "feature-branch" and updates your working directory to reflect the state of that branch. Now, any changes you make will be isolated to the "feature-branch" without affecting the main branch or any other branches.
  • 11. Branching in Git Listing Branches: ● To view all branches in your repository, use the following command: git branch ● This command will display a list of local branches, with an asterisk (*) indicating the currently active branch.
  • 12. Branching in Git Deleting a Branch: ● When a branch has served its purpose or is no longer needed, you can delete it using the git branch -d command followed by the branch name. However, note that you cannot delete the branch you are currently on. First, switch to a different branch and then delete the branch you wish to remove. ● To delete a branch, use the following command: git branch -d <branch_name> ● Replace <branch_name> with the name of the branch you want to delete.For example- git branch -d feature-branch ● This command will delete the "feature-branch" from your repository.
  • 13. Branching in Git Merging Branches in Git Resolving Conflicts
  • 14. Merging Branches in Git ● Merging is a fundamental process in Git that enables you to combine changes from one branch into another. ● It plays a crucial role in integrating new features, bug fixes, or improvements into the main branch or any target branch. ● This part of the chapter will delve into the intricacies of merging branches in Git, ensuring a smooth and efficient integration of changes. ● Merging branches in Git involves bringing the changes made in one branch into another branch.
  • 15. Merging Branches in Git ● This process consolidates the work done in different branches, allowing developers to synchronize their efforts and ensure that all relevant updates are incorporated into the final codebase. ● By merging branches, you can take advantage of parallel development, enabling different team members to work on separate features simultaneously. ● Git provides various strategies for merging branches, depending on the complexity and context of the changes.
  • 16. Types of Merges Fast-forward merges Automatic commit merges
  • 17. Merging Branches in Git Fast-forward Merge: ● A fast-forward merge is performed when the branch you want to merge has a linear commit history and there are no new commits in the target branch since the divergence. ● In this case, the target branch simply moves forward to include the new commits from the source branch. This results in a linear commit history, with all changes seamlessly integrated.
  • 18. Merging Branches in Git Fast-forward Merge: ● To perform a fast-forward merge, follow these steps: ● Switch to the target branch: git checkout <target_branch> ● Merge the source branch into the target branch: git merge <source_branch> ● Replace <target_branch> with the branch you want to merge into, and <source_branch> with the branch containing the new commits.
  • 19. Merging Branches in Git Fast-forward Merge: ● For example, let's say you have a feature branch named "feature-branch" and you want to merge it into the main branch. The following commands would accomplish this: git checkout main git merge feature-branch
  • 20. Merging Branches in Git Automatic Commit Merge: ● An automatic commit merge is performed when both the target and source branches have new commits since they diverged. ● Git creates a new commit that combines the changes from both branches, ensuring that all modifications are incorporated while maintaining a clear history of the individual branches.
  • 21. Merging Branches in Git Automatic Commit Merge: ● To initiate an automatic commit merge, use the following commands: ● Switch to the target branch: git checkout <target_branch> ● Merge the source branch into the target branch: git merge <source_branch> ● During an automatic commit merge, Git opens a text editor where you can enter a merge commit message. This message should provide a concise summary of the changes being merged.
  • 22. Merging Branches in Git Automatic Commit Merge: ● For example, if you want to merge a feature branch named "feature-branch" into the main branch, you would run the following commands: git checkout main git merge feature-branch
  • 23. Branching in Git Merging Branches in Git Resolving Conflicts
  • 24. Merge conflicts occur when Git encounters conflicting changes in different branches during a merge operation. Resolving these conflicts is an essential skill that every developer should master. Merge conflicts
  • 25. Resolving Merge Conflicts Identifying Conflicts: ● When a merge conflict occurs, Git modifies the affected files and marks the conflicting lines with conflict markers. These conflict markers help you identify the conflicting changes.
  • 26. Resolving Merge Conflicts Identifying Conflicts: ● Typically, Git uses the following markers: <<<<<<< HEAD ... Changes from the current branch ... ======= ... Changes from the incoming branch ... >>>>>>> incoming_branch ● The portion between <<<<<<< HEAD and ======= represents the changes made in the current branch, while the portion between ======= and >>>>>>> incoming_branch represents the changes made in the incoming branch.
  • 27. Resolving Conflicts: ● To resolve merge conflicts, follow these steps: ● Manually edit the conflicting files: Open the conflicting files in a text editor and locate the conflict markers. Review the conflicting changes and determine the desired outcome. ● Remove conflict markers: Remove the conflict markers and decide which changes to keep. You can choose the changes from either the current branch or the incoming branch, or modify the content to create a new version that combines both sets of changes. ● Save the changes: After resolving the conflicts, save the modified files.
  • 28. Resolving Conflicts: ● Committing the Merge: Once you have resolved all the conflicts, you need to stage the updated files and create a merge commit to finalize the merge operation. ● Add updated files to the staging area: Use the git add command to add the modified files to the staging area. This marks the resolved conflicts as ready to be committed. git add <file1> <file2> ...
  • 29. Resolving Conflicts: ● Create a merge commit: Use the git commit command to create a merge commit that incorporates the resolved conflicts and completes the merge operation. Provide a meaningful commit message that describes the changes made during the merge. git commit ● By following these steps, you can effectively resolve merge conflicts in Git, ensuring that conflicting changes are harmoniously integrated into the codebase.
  • 30. Branching in Git Merging Branches in Git Resolving Conflicts
  • 31. Lecture 3 Activity 1 Time for an activity.
  • 32. Lecture 3 Activity 2 Time for an activity.