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.
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.
To see the list of local branches.
To see the list all branches local and remote.
git branch -a
To create a branch.
git branch branch_name
To move into a branch.
git checkout branch_name
To create a branch and also move into it.
git checkout -b branch_name
To merge a branch.
git merge branch_name
To delete a branch that is merged.
git branch -d branch_name
- This is also called as soft delete.
To delete a branch that is not merged.
git branch -D branch_name
- This is also known as hard delete.
- Note-1: Whenever a branch is created, whatever is the commit history of the parent branch will be copied into the new branch.
- 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.
Generally, they ask this question to understand your branching knowledge .
- 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.
- 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.
- 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.