Git Branchs Management

,
Git Octo Cat

Git is a powerful tool that can help to manage code. But sometimes we don’t know or we are scared about the features aren’t know. At least is our code and don’t want to lose any line of them.

Following the previous git post: Basic Git commands, we talk about branches.

The branch is a powerful feature of git. If like we copy all code to a new directory and begin work there. But the main difference is that git knows how to join or merge these two directories without broke or lose any line of code and all in the same directory ;)

Then, we want to show how to manage branches and easiest that is.

First of all, we need to make a dir and init a new repository:

Now it’s time to create some code:

It’s time to see branches and create new ones:

Now we have two branches. Made some changes to hello.php, and test what happened:

Time to see differences:

We are in master and time to merge branches, now we say: merge second into master:

Merge two branches we don’t need the second branch, time to remove:

This kind of work with git gives us the opportunity to work in different code branch with different features, it’s like work in different directories without worry about mix code later.