Git branching and merging
Home > CentOS > CentOS 6.x > Versioning tools > git > 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
Show remote branches
To see list of all branches on remote server use:
git remote show origin
Add remote path
To add remote path (eg bitbucket) use following:
git remote add bitbucket git@bitbucket.org:sbarjatiya/servermanager.git git push bitbucket master
Checking out given branch
At any time we can chose to work on given branch by checking it out using:
git checkout <branch_name>
This would work to checkout origin branch even if there is no local branch with that 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
Home > CentOS > CentOS 6.x > Versioning tools > git > Git branching and merging