Git, Part II – Branches

Git, II° Parte – Branch

Git, II° Parte – Branch


In the previous article ( we dealt with the basics of Git but we did nothing but initialize a local repository and create our first commit. Now we have to proceed with the development and we have to keep track of the versions as the bugs are fixed. Today we see how the branches can help us.


What are


In the previous article we noticed that the commits are made on a timeline called “master”. This is the famous “time line” that allows us to return to the past should a critical bug appear. But suppose the project is very big: we can not afford to submit all commits in a single time line. It would be more appropriate to separate the workspaces for each sector of the project (front end, back end etc.) and to submit commit on separate lines leaving the original line intact. Good Git allows us and these lines are called Branches.


How to use them


Depending on the type of project the project manager can decide how to separate the sectors and how to organize the branches, I propose a model that in any case it is always useful to use.

Typically the master is the branch that takes into account all the versions released during development, so to speak when you read “Version 2.3” means the master branch (or the release branch) has remained at version 2.3 while the developers are programming on a separate branch the new version. When they complete the development, the procedure is to merge the development branch with the master / release branch and then release a new version. If you have not understood do not worry, read on:



This image clearly shows the power and usefulness of the branches. As we already know, the first commit of the project is done on the master branch (by default).
Now that we have a commit on the master and we want to continue developing, we need to create a branch on which to make changes to the next versions, typically called development.


Created development we can move on it. The next commits will then be recorded on this branch. But even this last branch works the same way as a master. From this we can create other branches, perhaps to implement new features without affecting the current project, and apply a new set of commits. When the feature is ready we can combine it with the development branch.


Hands on the terminal


Now we actually see how to create branches. For those wishing to avoid using the terminal further on I explain how to do for those who use GitKraken.


We create the branch:


git branch development


Now we move on it:


git checkout development


Small brackets, this procedure can be done with a single command:


git checkout -b development


Which takes care of creating and automatically selecting development as an active branch.


On GitKraken


GitKraken provides convenient tools for these operations, just click the right button on the branch from which we want to create a new bifurcation and click on “Create branch here”.
To move between the branches just select them from the menu at the top of the interface.


From here you are already able to make new commits with GitKraken. But I did not tell you how to add the files to be included in the commit using the terminal. That’s how:
Let’s take a look at the project:


git status


Git will show us all the files that have been modified, the added files and the deleted files. To add them to the list performed:


git add namefile1 namefile2 namefile3


or more quickly


git add *


if then from this list you want to exclude something performed


git reset file_da_non_includere


Do not worry if it seems like a whole new concept, in the next article I will gather the typically most used commands for any type of project so that you can consult it.

I’ll show you one last thing before leaving you. The linux operating systems are very numerous. While for Windows and MacOS we can only choose the current version, linux offers us a wide range of different operating systems, but all based on the same kernel.
Why do I tell you this? Because every Linux distribution is a branch!


Branches of Debian distributions




This is only a small part of the existing distributions, but as you can see, many bifurcations have been created from Debian, each of which has the same functionality as Debian, but can implement new features that are not found in Debian. Among the most famous Debian distros is Ubuntu. In turn, Ubuntu underwent bifurcations to create distros like Kubuntu, Xubuntu, Edubuntu, Lubuntu and so on.


For today we have finished, share if you found it useful!
Here SviluppoMania, step and close.




Copyright © SviluppoMania. All rights reserved.



SviluppoMania - Francesco Candurro

Related Posts

This site uses Akismet to reduce spam. Learn how your comment data is processed.