Git branching and merging

From Notes_Wiki
Revision as of 10:59, 5 November 2013 by Saurabh (talk | contribs)

<yambe:breadcrumb>Git</yambe:breadcrumb>

Git branching and merging

Creating, merging and deleting branches with git is very easy.


Creating a new branch

To create a new branch of development we can use:

git branch <branch_name>


Listing existing branches

To list all existing branches we can use:

git branch 


Checking out given branch

At any time we can chose to work on given branch by checking it out using:

git checkout <branch_name>


Merging current branch with some other branch

To merge current branch with some other branch we can use:

git merge <other_branch_name>

after checking out current branch.

If merge is successful then commit is done with new merge automatically. However if there are conflict then CONFLICT error messages are shown. To see the conflicting lines after merge we can use

git diff

command which lists conflicting lines. In such cases 'git status' shows files with conflict as 'unmerged paths'.

In case of conflicts we should edit the conflicting files to remove the conflicts. Then we should use 'git add <modified_file>' to add the new modified file to index. Then finally 'git commit' to commit resolved file to repository.



Deleting a branch

We can delete a branch (probably after it has been merged with master) using

git branch -d <branch_name>


A good tutorial on git is located at http://www.vogella.com/articles/Git/article.html


<yambe:breadcrumb>Git</yambe:breadcrumb>