Git branch learning note and git branch note

Source: Internet
Author: User

Git branch learning note and git branch note

Introduction

After two times of Git content, I forgot the concept of branch in the next day and thought it was not very useful. Then I read it again to find out why it is an extremely important thing in Git.

The so-called branch is similar to the branches of a tree. It has a trunk and becomes a master in Git, which is also easy to understand. This must exist, then you can separate other trunks (but none of them are trunk trees ). Just as the branches of the tree will return to the trunk, the branches in Git will also converge to the master.

For example, we now have ready-made code. A wants to modify it, but it cannot be changed directly. You can copy it and modify it. In Git, we can directly create A branch. After I think it is perfect, I will upload it to the past. This can be done by directly merging branches.

Common branch commands and functions

The git branch command can be used to view the current branch status, * representing the current branch

# git branch* master   test

We can see that we have two branches, one master and one test.

With git checkout test, we can switch to the test branch.

#git checkout testSwitched to branch 'test'
#git branch
master
*test

Through the git checkout-B xx command, we can create xx branch.-B indicates creation and direct switch to xx branch.

Using git merge xx, You can merge xx branches into master branches.

After merging, you can delete the xx branch and use the git branch-d xx command. Note that the conflict must be resolved during merging (that is, the content inconsistency problem)

 

The following is a complete example (the Code highlight is not ideal. Let's take a look:

07:02:01wang@~/Documents/git >>  git branch  master* test07:02:11wang@~/Documents/git >>  git checkout  masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 1 commit.  (use "git push" to publish your local commits)07:02:21wang@~/Documents/git >>  git branch* master  test07:02:27wang@~/Documents/git >>  lsreadme.txt  Spoon-Knife  test07:02:45wang@~/Documents/git >>  cat readme.txtmaster branch`07:02:51wang@~/Documents/git >>  git checkout -b test1Switched to a new branch 'test1'07:03:02wang@~/Documents/git >>  git branch  master  test* test107:03:05wang@~/Documents/git >>  lsreadme.txt  Spoon-Knife  test07:03:07wang@~/Documents/git >>  vi readme.txt07:03:18wang@~/Documents/git >>  git add readme.txt07:03:23wang@~/Documents/git >>  git commit -m "branch test1"[test1 3a09722] branch test1 1 file changed, 2 insertions(+)07:03:38wang@~/Documents/git >>  git checkout masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 1 commit.  (use "git push" to publish your local commits)07:03:53wang@~/Documents/git >>  git branch* master  test  test107:03:56wang@~/Documents/git >>  git merge test1Updating c7ac8a8..3a09722Fast-forward readme.txt | 2 ++ 1 file changed, 2 insertions(+)07:04:02wang@~/Documents/git >>  cat readme.txtmaster branch`test1 branch07:04:07wang@~/Documents/git >>  git branch -d test1Deleted branch test1 (was 3a09722).07:04:18wang@~/Documents/git >>  git branch* master  test

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.