GIT branch Management

Source: Internet
Author: User

Branch is like a person has ubiquitous, one is learning English, one is studying mathematics, when the meta-God is one, you learn two things at the same time.

What is the use of branching in real-world development? Assuming that you develop a feature, your code will take two weeks to finish, but you'll be able to commit some of the code on a branch every day to affect others ' inability to work.

But when you finish writing, others develop it, which affects the progress of the development. Now it's not afraid to have a branch. You create a branch of your own that no one else can see. When you are finished, then

Merge to the original branch at once. This is both safe and does not affect the work of others.

Other version control systems, such as SVN, have branch management, but after use you will find that these version control systems create and switch branches slower than the tortoise, which is unbearable,

As a result, the branching function became a device, and everyone was not using it.

But Git's branch management is different--whether it's creating, switching, and deleting branches, git can do it quickly.

First, we create the dev branch and then switch to the dev branch:

$ git checkout-b dev
Switched to a new branch ' Dev '

Equivalent to the following two commands:

$git Branch Dev

$git Checkout Dev

Then, use the GIT branch command to view the current branch:

$ git Branch
* Dev
Master

The git branch command lists all branches, preceded by an * number in front of the current branch.

We can normally submit it on Dev, like making a change in Readme.txt, plus a sentence:

Add Dev Branch Content

Now let's cut back to the master branch:

$ git Checkout Master
Switched to branch ' master '
Your Branch is ahead of ' Origin/master ' by 1 commit.
(use "Git push" to publish your local commits)

[Email protected] Mingw32/c/gitskill (Master)
$ ls
README.MD Readme.txt

[Email protected] Mingw32/c/gitskill (Master)
$ cat Readme.txt
Master Branch Content

We will find that after switching to the master branch, the content just added is missing because that commit is on the Dev branch, and the Master branch's commit point is not changed at the moment.

We merge the work on the Dev branch onto the master branch:

$ git Merge dev
Updating D5aea29. 0d0bbca
Fast-forward
Readme.txt | 3 ++-
1 file changed, 2 insertions (+), 1 deletion (-)

Then look at the Readme.txt file under the master branch:

[Email protected] Mingw32/c/gitskill (Master)
$ cat Readme.txt
Master Branch Content
Add Dev Branch Content

Once the merge is successful, you can safely delete the dev branch:

[Email protected] Mingw32/c/gitskill (Master)
$ git branch-d dev
Deleted Branch Dev (was 0D0BBCA).

[Email protected] Mingw32/c/gitskill (Master)
$ git Branch
* Master

Summary: Because creating, merging, and deleting branches is very fast, git encourages you to use a branch to complete a task, and then delete the branch after merging, which works directly on the master branch.

The effect is the same, but the process is more secure.

View branches: Git branch

Create a branch: Git branch <name>

Switch branches: git checkout <name>

Create + Switch branch: git checkout-b name

Merging certain branches into the current branch: git merge name

Delete branch: git branch-d name

GIT branch Management

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.