We talked about Git earlier. Git is an open source program used for version control of the source code. In general, we can say that Git is perhaps the best in its area. It has a lot of community support, its learning is really easy and it has an unmatched performance. In addition to all this is open soource and is available for almost all current operating systems. However, Git’s true power lies in the development branches that make it very versatile and tidy. Therefore, in this post, we will outline an introduction to the Git branches.
The Git branches
Today, any version control program must know how to implement development branches. It is understood by a development branch to a timeline of the code independent of the main branch. For example, we can create a master branch and then an unstable call. Where in the unstable branch we can go incorporating all the characteristics and code that we want without affecting all the work of the main branch. So with this, there is an independence of the code and allows us to make regressions without any problems.
Normally, developers do not incorporate all the features into the source code at once. If they do not take a solid stable base and start creating branches of developments whenever they need it, then they can always have the original code without errors.
So, let us start.
The master branch: Initializing the project
First, you need to install Git. For this, you have two articles on our site that will help you to do it without any problem.
If you use Debian 9 this article is for you.
Or, if you are using Ubuntu, then this is the right.
Then, create a new folder for the project.
:~$ mkdir program1
Next, init the git project with this command:
:~$ git init
At this moment, our project has already been started and we can start working. However, it is necessary to make the first commit to start using the development branches. So, let’s get started.
:~$ cd program1 && touch README LICENSE :~$ git add README LICENSE :~$ git commit -m "Initial commit"
First steps using the Git Branches
Now, the first development branch, the master, has been implicitly created. Where all the bulk of our project goes. If you want to show all the development branches that are on a project, run the following command:
:~$ git branch
And to create a new branch, use the following command:
:~$ git branch new_brach
Now the branch is created but you need to tell Git we are going to work with it. In other words, you have to change the development branch.
:~$ git checkout thebranch
Now, you can work normally on that development branch and it will not affect the main or master branch. Of course, there comes a point where the changes are already mature and it is necessary to join them with another branch. To do this, switch to the master branch and run:
:~$ git checkout master :~$ git merge thebranch
So, these are the basic of git branches. Create, changes and merge.
Conclusion
With this post, we don’t expect you to be an expert in Git branches but it does serve as a small introduction to the subject. Of course you can also use Git with other applications that provide a graphical interface like GitKraken.
So share this post with your friends.