【Git+Source Tree使用教程之二】Branching & Merging

Current git graph

Now we want to create a new branch called dev from our master branch. Here is our current state of our git graph before the branching:

【Git+Source Tree使用教程之二】Branching & Merging_第1张图片  



Creating a dev branch

To create a new branch (dev), we need click "Branch" on the top menu.

【Git+Source Tree使用教程之二】Branching & Merging_第2张图片  

Hit "Create Branch", then our git looks like this:

【Git+Source Tree使用教程之二】Branching & Merging_第3张图片  


Pushing the dev branch to GitHub

Let's push our new dev branch to our remote repo:

【Git+Source Tree使用教程之二】Branching & Merging_第4张图片  
【Git+Source Tree使用教程之二】Branching & Merging_第5张图片  

After the dev branch push, we can check our GitHub now has two branches: master and dev branches:

【Git+Source Tree使用教程之二】Branching & Merging_第6张图片


Committing to the new dev branch

If we want to commit a new file (myfile04.txt) to our new dev branch:

【Git+Source Tree使用教程之二】Branching & Merging_第7张图片  

 

Pushing to Dev branch:

 

【Git+Source Tree使用教程之二】Branching & Merging_第8张图片  

After another push:

【Git+Source Tree使用教程之二】Branching & Merging_第9张图片  



Feature Branch

When we want to add major feature, it's better work on a separate branch. So, we will create a new branch called feature1 from the dev branch:

【Git+Source Tree使用教程之二】Branching & Merging_第10张图片  

【Git+Source Tree使用教程之二】Branching & Merging_第11张图片  

After two more commits to our new feature1 branch:

【Git+Source Tree使用教程之二】Branching & Merging_第12张图片  

Pushing feature1 branch to GitHub:

【Git+Source Tree使用教程之二】Branching & Merging_第13张图片  

 



Current branch

We can select current branch by double clicking a branch under "Branches" side menu. We can tell by itsbold font face.

dev branch is the current branch:

【Git+Source Tree使用教程之二】Branching & Merging_第14张图片  

master is the current branch:

【Git+Source Tree使用教程之二】Branching & Merging_第15张图片

Before we do merge feature1 to dev, to make it more interesting, we want to do additional commit to devand push to GitHub:

【Git+Source Tree使用教程之二】Branching & Merging_第16张图片  



Merge Feature Branch into dev branch

After working on feature1 branch, now we want to merge it into dev branch. Set dev branch as the our current branch.

【Git+Source Tree使用教程之二】Branching & Merging_第17张图片  

【Git+Source Tree使用教程之二】Branching & Merging_第18张图片

Hit "OK":

【Git+Source Tree使用教程之二】Branching & Merging_第19张图片

Now, feature1 branch merged into dev branch.

原文链接:http://www.bogotobogo.com/cplusplus/Git/Git_GitHub_Source_Tree_2_Branching_Merging.php

你可能感兴趣的:(git,gitlab,merge,branch,SourceTree)