【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:

SourceTreeBeforeDevBranch.png 



Creating a dev branch

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

CreatingDevBranchDialog.png 

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

DevBranchCreated.png 


Pushing the dev branch to GitHub

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

PushingDevBranchToGitHub.png 
PushingDevBranchToGitHubDialog.png 

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

GitHubAfterPushingDevBranch.png


Committing to the new dev branch

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

CommitingToDevBranch.png 

CommitedMyFile04.png 

Pushing to Dev branch:

PushingToDevBranchDialog.png 

PushedToDevBranch.png 

After another push:

After5thPush.png 



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:

CreatingFeature1BranchDialog.png 

Feature1BranchCreated.png 

After two more commits to our new feature1 branch:

AddedTwoMajorFeaturesToFeature1Branch.png 

Pushing feature1 branch to GitHub:

PushFeatureBranchToGitHub.png 

AfterPushingFeature.png 



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:

MasterIsCurrentBranch.png 

master is the current branch:

DevIsCurrentBranch.png

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

OneMoreCommitToDev.png 



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.

FeatureMergeIntoDevDialog.png 

FeatureMergeIntoDevDialog2.png

Hit "OK":

Feature1IntoDev.png

Now, feature1 branch merged into dev branch.

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

發佈了106 篇原創文章 · 獲贊 24 · 訪問量 132萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章