

Only the update of the branch pointer occurs to match the merged branch.įinally, we need to push the changes to the remote repository. In the case of the fast-forward merge, no merge commit is created. It also causes to group together all the commits of the feature branch.Īlso, when we desire to revert the merge of the feature branch into the main branch, it is easier because of the presence of the merge commit. It’s useful, as when we browse the Git history, we would see information about the existence of the feature branch. It causes to create a merge commit in all cases, even when the merge could be resolved as a fast-forward. The -no-ff option to the command git merge always enforces to create a new commit object, even if a fast-forward merge is performed. We will use the git merge command to merge the feature branch with the main branch. We can use the git merge command to merge the feature branch with the mainline branch main.įirst, we would switch to the mainline branch main using the git checkout command. Now we would develop the new feature and make our changes in the new branch, namely feature.Īfter completing the feature development and committing the changes to the new branch feature, we would like to merge this branch with the mainline branch main. Also, it causes the new branch to be checked out. The option -b to the command git checkout causes the new branch to be created. Thus, we have created a new branch feature off the existing branch main. In our case, we will execute the command as follows. The syntax to create a new branch of the existing branch is below. We can use the git checkout command for that. Suppose we want to create a branch feature from the mainline branch main for developing a feature. Once the team or team members are satisfied with the changes done in the new branch, the new branch is often merged back into the mainline branch. Another team or team member would create a branch feature for developing a new feature. A bug fix team would create a new branch named bugfixes on top of that branch. Suppose we have a mainline branch named main in our project repository. Various team members or teams may create different branches from an existing branch to work on that branch. We have multiple team members or teams using the same project repository for work in a collaborative development environment. Git, a distributed version control system, is a useful tool for tracking changes to the project repository. Use the git checkout Command to Create Branch From Another Branch in Git Also, we can merge the branches using Git commands. Git provides us the capability to create a branch from another existing branch. After completing the task, we typically merge this branch back to the mainline branch for a release. We often create a new branch from the mainline for fixing bugs or developing a new feature.
