Version control git (iii)-GIT branch

Source: Internet
Author: User
Tags how to use git git commands

Through the previous two articles in this series (see series: HTTP://WWW.CNBLOGS.COM/JEREHEDU/P/4607599.HTML#BBKZ), we already know how to use Git to do version control of the file. This time we continue to learn how to manage branching through git.

First, we need to figure out what a branch is. With the git log command we can view the repository's commit log,

So what's the relationship between these commits? In fact, each commit, the commit object will save a pointer to the last commit version, after several commits, git through this pointer to the multiple commit version string into a string, such as:

Branching is actually a history that moves forward from a commit version, so far there is only one branch of git, which we call the main branch, and the default name is master. Every time you submit, Master moves forward, pointing to the latest commit version.

Create a new branch

So in git, how do we create new branches, it's very simple to use git commands:git branch branch names.

This allows us to create a branch named: jredu_branch_01, and note that this branch is built on the current commit version object, as shown in:

Now that we have two branches, how does git know the current working branch? In fact, Git holds a special pointer called Head, which points to the current working branch.

Switch branches

Using "Git branch branch name" just creates a branch, does not switch to the new branch, if you want to switch branches, we should use the command:git checkout branch name

After switching, head points to the jredu_branch_01, as follows:

We work under the Jredu_branch_01 branch, and after adding a new file by command "git add" and "Git Commit", the new branch is as follows:

You can see that the new branch jredu_branch_01 a step forward, while the master branch master still stays on the original version.

View Branches

There are multiple branches in git, how do you see and know the current work branch? View commands:git branch

You can see a total of two branch master and jredu_branch_01, "*" indicating the current working branch.

Merging branches

With branching, we can easily collaborate on development so that multiple branches can be generated, so how do we do branch merging? Git-provided merge commands:git merge merged branch

The first step is to return to the Master branch and run the merge command next:

This allows us to merge the Jredu_branch_01 branch onto the master branch.

Delete Branch

JREDU_BRANCH_01 Branch is merged into master, there is no use, here we can choose to delete it, git delete branch of the command:git branch–d to delete the branch

Merge conflicts

In the process of merging branches, if you encounter different branches to modify the same files, then the merge will not be so smooth, often see the following information:

At this point git does a merge, but does not commit, it needs to resolve the conflict before committing. We can see the conflicting files through the git status command

Open the conflicting file and we see the specific file content

The file uses "=========" to split the conflicting portions of different branch file modifications, and the "<<<<<<<

After modifying the file, use the git add command and use git status to view the conflict status and finally commit.

This solves the problem of the conflict and completes the final merger.

  Summarize the commands associated with the GIT branch

Create branch: GIT Branch branch name

Toggle Branch: Git Checkout branch name

View branches: Git branch

Merge branches: Git merge branch to merge

Delete branch: git branch–d to delete a branch

Inquiries or technical exchanges, please join the official QQ Group: (452379712)

Jerry Education
Source:http://blog.csdn.net/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Version control git (iii)-GIT branch

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.