by BehindJava

What is Branching Strategy and its types in GIT

Home » interview » What is Branching Strategy and its types in GIT

In this tutorial, we are going to learn about Branching Strategies in detail i.e., Branching is a feature of git that allows you to create separate branches for different functionalites and later merge them with the main branch also known as the master branch. This will help in creating the code in an uncluttered way so that each task can be implemented on its own branch.

Branching in Git

This is a feature of git using which we can create seperate branches for different functionalites and later merge them with the main branch also known as the master branch.This will help in creating the code in an uncluttered way.

  1. To see the list of local branches.

    git branch 
  2. To see the list all branches local and remote.

    git branch -a 
  3. To create a branch.

    git branch branch_name 
  4. To move into a branch.

    git checkout branch_name 
  5. To create a branch and also move into it.

    git checkout -b branch_name 
  6. To merge a branch.

    git merge branch_name 
  7. To delete a branch that is merged.

    git branch -d branch_name 
    • This is also called as soft delete.
  8. To delete a branch that is not merged.

    git branch -D branch_name 
    • This is also known as hard delete.
  9. Note-1: Whenever a branch is created, whatever is the commit history of the parent branch will be copied into the new branch.
  10. Note-2: Irrespective of, on which branch a file is created or modified git only considers form which branch it is commited and the file belongs to that commited branch only.

Types of Branching Strategies

Generally, they ask this question to understand your branching knowledge .

  1. Feature branching: This model keeps all the changes for a feature inside of a branch. When the feature branch is fully tested and validated by automated tests, the branch is then merged into master.
  2. Task branching: In this task branching model each task is implemented on its own branch with the task key included in the branch name. It is quite easy to see which code implements which task, just look for the task key in the branch name.
  3. Release branching: Once the develop branch has acquired enough features for a release, then we can clone that branch to form a Release branch. Creating this release branch starts the next release cycle, so no new features can be added after this point, only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it’s ready to ship, the release gets merged into master and then tagged with a version number. In addition, it should be merged back into develop branch, which may have progressed since the release was initiated earlier.