BRANCHING AND MERGING

Branching

Branch operation allows creating another line of development. We can use this operation to fork off the development process into two different directions. Branching is used in Version control and software management to maintain stability while isolated changes are made to code. Branching facilitates the development of bug fixes, the addition of new capabilities and the integration of new versions after they have been tested in isolation.

Create Branch

we can create a branch by using a command git branch branchName.

Example :

git branch text

Example :

Create Branch

In above example, Git shows an asterisk mark before currently working branch.

Switch between Branches

We can switch between branches by using a command git switch branchName.

Example :

switch Branch

Delete a Branch

We can delete a branch by using a command git branch -D branchName. But before deleting the existing branch, switch to the other branch.

Example :

delete Branch

Merging

Merging is a common practice for developers using version control systems. Whether branches are created for testing, bug fixes, or other reasons, merging commits changes to another location. To be more specific, merging takes the contents of a source branch and integrates them with a target branch. In this process, only the target branch is changed. The source branch history remains the same.

Example :

  • Created a index.html in master branch.
  • Created a branch named test
  • The same index.html is duplicated in test branch(means the test branch will have same copy of code which master branch contains).
  • After that changed p tag content in index.html (master as test) in test branch. As shown in below figures.
  • master Branch
    test Branch
  • Go to github repository, click on compare & pull request.
  • compare & pull request
  • Click on Create pull request
  • pull request
  • Click on View pull request
  • compare request
  • If there are any conflicts then resolve them by clicking on Resolve conflicts.
  • Remove all arrows and equal symbols.
  • Click on Commit merge.
  • Click on Merge pull request.
  •  Merge pull request
  • Click on Confirm merge
  •  Confirm merge
  • Check whether merge is successful or not and delete the test branch.
  • delete Testbranch
  • Now you can see that test branch content is merged with master branch content in below fig.
  • merged