Saturday, March 29, 2014

About Branch in Git

What is branch in git.

Earlier  I did not know about branch, probably still need to more explore about this, however I am going to write some words for this.
Branch is a separator, created for  particular task while we are working on git. Every project has master branch, various task, improvements, bugs in git.

We created the sub branch for each new task, after completed this task we will do merge that branch along with the master branch.

Why we need to do branch?

Suppose we have a project, "File Tracking System", Now there is a bug  raised #213 and one of the developer is fixing this bug with created sub branch named 'bug-213', We supposed there is up-do-date code existing into git, and at the same time, there is critical new bug is came and need to fix that first, We'll have to work on this issue first and should work on other bug at later.

Now we do switch to main branch from working branch('bug-213') and fix that new bug and update it into git. Now we would like to work on earlier bug #213 so we do switch back to branch 'bug-213' from master branch. After fixed this problem, we will do merge this working branch to master branch.

One point need to be careful here that if  same file is modified in branch 'bug-213' and in a file(during the fixed of new bug) then there would be the conflict during the merge, we have to resolve that conflict first and do merge this branch 'bug-213' to master branch.

Here how do we create, switch and merge the branch.

For create a branch named bug-213
git checkout -b bug-213

For switch to branch bug-213
Switched to a new branch bug-213

For switch to master branch
git checkout master
Switched to branch 'master'

When you are in master branch run this command for merge bug-213 branch to master branch.
git merge  bug-213

After merged the branch successfully, you can remove this branch by

For remove the branch locally
git branch -d bug-213

For remove the branch remotely
git push origin : bug-213

I will do update the article when will do more explore more about topics.