Branching in GITHUB

GITHUB is a version control tool which is what i understood from my learning. It is the place where we can find the snapshots of all the changes done in the process of making any projects.

GITHUB is the place where we can go and see what changes are done in the repository. (Repository is like folder where we can store some files),who has done those changes and when exactly.

Developers including me use this tool in their day to day life.but recently i came to know about branching in the GITHUB which is similar as taking diversion from the main line and do some task and come back again.

BRANCHING IN GITHUB

image.png

Picture this tree as a Git repository. It has a lot of branches, long and short, stemming from the trunk and stemming from other branches. Let's say the tree's trunk represents a master or main branch of our repo.

Branching comes into the picture for mostly two reason:

  1. If you are creating a new feature for your project, there's a reasonable chance that adding it could break your working code. This would be very bad for active users of your project. It's better to start with a prototype, which you would want to design roughly in a different branch and see how it works, before you decide whether to add the feature to the repo's master for others to use.

  2. Another, probably more important, reason is Git was made for collaboration. If everyone starts programming on top of your repo's master branch, it will cause a lot of confusion. Everyone has different knowledge and experience (in the programming language and/or the project); some people may write faulty/buggy code or simply the kind of code/feature you may not want in your project. Using branches allows you to verify contributions and select which to add to the project. (This assumes you are the only owner of the repo and want full control of what code is added to it. In real-life projects, there are multiple owners with the rights to merge code in a repo.)

MERGING IN GITHUB

If we are done with our changes and tested it successfully, we tends to merge our existing branch to the main or master branch. Doing this we are adding the changes we made in our branch to the main branch.

Steps involves in merging:
  1. We create a compare and pull request. This steps allows us to view the difference in code between main branch and branch we created.
  2. If there is no conflicts happen then we can go ahead and merge the request and confirm the same.

Its a good practice to make github in our daily use as a developer. Every company follow one such tool to have the track of the changes related to projects.