Managing branches

By default, when creating a repository, the code is placed in the main branch called master. In order to be able to isolate the developments of the master branch, for example, to develop a new feature, fix a bug, or even make technical experiments, we can create new branches from other branches and merge them together when we want to merge their code.

To create a branch from the current locally loaded branch, we execute the following command:

git branch <name of the desired branch>

To switch to another branch, we execute the following command:

git checkout <name of the branch>

This command changes the branch and loads the current working directory with the contents of that branch.

To merge a branch to the current branch, execute the merge command, as follows:

git merge <branch name>

With the name of the branch, we want to merge as a parameter.

Finally, to display the list of local branches, we execute the command branch:

git branch

Branch management is not easy to use from the command line. The graphical tools of Git, already mentioned, allow better visualization and management of the branches. We will see their uses in detail in the next section, which will deal with the Git process. That's all for the usual Git command lines, although there are many more to handle.

In the next section, we will put all of this into practice by applying the work and collaboration process with Git, and look at an overview of the GitFlow pattern.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.30.162