Git distributed control version system, also know for source code management capabilities, is well established when it comes to branching. The term Git branching refers to the way a developer diverges from the line of development but continues to do work without messing up with the original main line. Branching with Git tool is now simplified and delivers as compared to other control version tools. Branching process is quite expensive since one has to come up with a copy of their source code directory that somehow consumes time when working on large projects.
Among the available control versions repositories, Git branching model leads by far which has led to its nickname “Killer feature.” It is special in the CVS community due its unbelievably lightweight, making branching operations simpler and faster almost to instant response. Git branching allows you to switch back and forth between branches in an incredible fast swap. Understanding and mastering this Git’s killer features will revolutionize your entire approach to your coding life.
What is branching?
In software development, branches are used to develop features kept apart from each other. There is the default branch, also known as the master branch while creating a repository, and other branches for development. These branches are merged back to the master branch up on completion.
figure: 1.0 shows basic branching and merging
How does this apply in the current day to day life? Check out a few steps bellow:
a) Do some coding on a web site
b) Create a branch for the new code you are working on
c) Do some changes on that branch
While you are working on this branch, you’re notified that an other issue is critical that need a hotfix. You will follow the procedure below in order to tackle it:
a) Turn back to your production branch
b) Create a branch to add the hotfix
c) Test it, and then merge the hotfix branch and continue to production
d) Switch back to your master branch and continue working.
Understanding the way Git branching is carried out is very important to your development. You need to know how Git stores its data, and also familiarize yourself with Git deltas (changesets) and snapshots. For instance, Git store data as a series of snapshots and not as a series of deltas.
Types of branches in Git.
Git branching can be subdivided into two categories. There is the Main branches and the supporting branches.
a) Main branches
They are namely: Master branch & Develop branch. All developers are familiar with master branch and even have used it. But there is also an other parallel branch known as “develop.” The difference between this two branches is the HEAD. In master branch, the head source code always mirrors a production ready state. While in develop branch, the head source code always mirrors a state with the latest delivered development changes for the next release.
However, when the changes in the develop branch reaches a stable point ready to be released; all the changes should be merged back into the master branch together with the release number (normally tagged).
b) Supporting Branches
Unlike the main branches, supporting branches always have a limited lifetime since they are usually delete eventually. These branches include: Feature branches, which are use to develop new features for the future release; Release branches, which support operation of a new production release; and lastly but not the least Hotfix branches. Early in this article we saw how hotfix branch is created and for what reason. Hotfix branch operate almost similar to release branches but in this case, it’s unplanned.
They are used to handle specific task during development and must be merge back into the master branch.
Git branching and merging
Branching and merging in the Git control version control system gives a nice experiences for dummies. In Git, branches are simply context which you can switch between. And this is the most crucial difference between other control versions like subversion. Because in subversion, a branch is simply a sub-directory within your repository. So if you want to check out how to branch you really need to pre-set sets of files.
But within Git, a branch is a context you can switch to using features like Git command branch. Command branch lists all branches you’re currently working on. Also it provides you with ample space to create new branches, switch back and forth between them, and also merge them on a normal workflow.
Conflicts and solving them.
Branching and merging is really effortless. Besides switching between branches, in Git, solving conflict is something lightweight that shouldn’t bother you at all. Git provides clear view of conflicts and the conflicting files. The conflicted file is easily identified and you can start working on it without wasting time.
As we’ve already seen, Git branching is something interesting that lets you just flow with it. While working on a number of branches, checkouts allows you to navigate from one branch to another. Checkouts grands easy switch from the master branch and back without interrupts. Additionally, checkouts constantly updates the file in the working directory to be in line with the version store in that particular branch. Git checkout command is useful before merging process
Deleting Git branches.
Every time you finish working on a branch and merge it to the master branch (or main code), you are allowed to delete that branch without losing any history. Any attempt to delete a branch which is not merged, you will get an error message prompt, notifying you that the branching you’re trying to delete is “not fully merged.” However, you can as well force delete a branch regardless of its status and without git warnings.
Branching rebase in Git
Rebase is merging of more than two branches. Normally, rebasing is applied when you have to merge 3-way branches between two branch latest snapshot. The are different types of rebasing as depending to the kind of project you’re working on.
In conclusion, Git branching is what makes Git stand out of other control versions. Yet we’ve seen how friend it is to use Git branching regardless of whether you’re are an expert developer or new into development. For beginners out there, Git branching welcome you with unbelievable easy branching techniques that will ignite your potential.