[Git]git's branch management

Source: Internet
Author: User

Recently tossing git, feeling about git this powerful and useful version management tool.

Talk about Git branch management experience.

First, you have a master Master branch:


The name of the GIT Main branch, which is called Master by default. It is built automatically, and after the repository is initialized, the default is to develop in the main branch.

Git's "master" branch is not a special branch. It is no different from the other branches at all. Almost every warehouse has a master branch because the git init command creates it by default, and most people are too lazy to change it.

In daily Development, another branch, the Dev branch, is used primarily for development, while Master is primarily used for major releases.

How do I create a dev branch?

Simple, with the command:

git checkout-b dev Master

This command means: Create a branch branch from the Master Master branch: Dev

In the development process, how to merge the development Branch Dev into the master branch master?

With two commands:

# Switch to Master branch
git checkout Master

# Merging the Dev branch
git merge--no-ff Dev

What does the--NO-FF parameter of the previous command mean?

By default, Git performs a fast-forward merge (Fast-farward merge) that directly points the master branch to the Dev branch.

Let me give you an example:

If we have a branch of this version:

Now that you have an urgent bug to fix, let's set up a branch for that urgent problem (hotfix branch) to work on that branch until the problem is resolved:

$git checkout Master

$Git checkout-b Hotfix
现在我们根据master创建了一个hotfix分支,如果我们在这个hotfix分支把问题修复,
并提交:

$
‘fixed the broken email address‘

At this point, the branch chart becomes:

Now how do you merge hotfix's branches into master?

Execute command:

First switch to the master branch with the checkout command:

$git checkout master 

然后,把hotfix分支合并到master:
$
git merge hotfix

This time, the branch chart is this:


After the solution to this urgent problem is released, you are ready to go back to the work that was before the interruption. However, you should remove the hotfix branch first, because you no longer need it-the master branch is already pointing to the same location. You can use -d the command with options git branch to delete a branch:

$Git branch-d Hotfix

At this time, to make a tag:

Git tag-a 1.2 (using the-U/-S/-A parameter creates a tag object, not a soft tag)

Make sure to tag this new submission on Master (record milestone)

Tag tag is a marker for a point-in-time version and is often used for release.

[Git]git's 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.