Difference between revisions of "Git branching and merging"

From Notes_Wiki
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<yambe:breadcrumb>Git</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Versioning tools]] > [[Git|git]] > [[Git branching and merging]]
=Git branching and merging=


Creating, merging and deleting branches with git is very easy.  
Creating, merging and deleting branches with git is very easy.  
Line 19: Line 18:
git branch  
git branch  
</pre>
</pre>
==Show remote branches==
To see list of all branches on remote server use:
<pre>
git remote show origin
</pre>
==Add remote path==
To add remote path (eg bitbucket) use following:
<pre>
git remote add bitbucket git@bitbucket.org:sbarjatiya/servermanager.git
git push bitbucket master
</pre>




==Checking out given branch==
==Checking out given branch==
At any time we can chose to work on given branch by checking it out using:
At any time we can chose to work on given branch by checking it out using:
<pre>
<pre>
git checkout <branch_name>
git checkout <branch_name>
</pre>
</pre>
This would work to checkout origin branch even if there is no local branch with that name




Line 61: Line 76:




<yambe:breadcrumb>Git</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Versioning tools]] > [[Git|git]] > [[Git branching and merging]]

Latest revision as of 15:42, 24 August 2022

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