Git branch management

Source: Internet
Author: User

Git branch management

Outline:

1. Preface

2. Create a branch

3. Switch Branch

4. merge branches (fast merge)

5. Delete Branch

6. Branch merge conflicts

7. Merge Branch (Common merge)

8. Branch Management Policy

9. development collaboration among multiple teams

10. Summary

Note: CentOS 5.5 x86_64, Git server version: git version 1.8.2.1, and Client version: git version 1.9.2.msysgit.0. Download all the software here: http://msysgit.github.io /.

1. Preface

In the previous blog, we mainly explained the Git remote repository. I believe you have some knowledge about the remote Git repository. In this blog, we will explain Git branch management, which is another major feature of Git. Next let's take a look at Git branch management.

Let's talk about a simple case first. There are multiple people in your team who need to develop a project. It takes one week for a colleague to develop a new function, he has not finished writing 30% of this version. If he submits this version, other people in the team will not be able to continue development. But when he finishes writing all the work and submits all the work, no one can see his development progress, and he cannot continue to work. How can this be done?

For this problem, we can use the branch management method to solve it. A colleague develops a new function, and he can create a branch of his own. Other colleagues cannot see it for the moment, he continues to work on the Development Branch (generally with multiple branches). He works on his own branch. After all the development is completed, the Branch will be merged to the Development Branch at one time, in this way, we can know the development progress without affecting everyone's work. Is it very convenient?

As you may say, SVN is also available for your Git Branch functions, and there is nothing special about it. But I want to talk about how quickly you can create and switch between them? Hey, I want to know who is using it! But in Git, no matter whether you create or switch or delete it, it will be very fast!

In essence, a branch is a variable pointer pointing to a certain commit. The default branch name of Git is master. But how do we know which branch is currently in? The answer is that HEAD is a very special pointer dedicated to pointing to the current branch in the local branch. We can simply understand it as: commit <-branch <-HEAD (note, we have already described the HEAD in detail. It's really hard to say this thing. If goole is done, few experts will say this, hey. Next, I will explain how to help you understand. Simply put, HEAD points to the current branch in the local branch. For example, we will create the branch below.

GitHub Tutorials:

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

2. Create a branch

When we need to debug a Bug or try to add or modify a module in the program, but it does not affect the development of the main branch. You can create a branch to meet your requirements. Creating a branch is equivalent to creating a new branch pointer pointing to the current submission. We create the dev branch on Commit3:

As shown in, the dev branch points to commit3.

We can see that although we have created a new branch, the HEAD still points to the master. If you want to switch to the new branch when creating the branch, run the following command:

Add the-B parameter to the git checkout command to create and switch the branch.

 

3. Switch Branch

To switch the current branch, run the following command:

The git branch-a command can be used to view all branches. Now the HEAD Pointer Points to the dev branch. You can see that there is a * number on the dev branch.

Next, modify the content in readme.txt and submit it on the dev branch. For example:

Use a flowchart to demonstrate the process as follows:

Now we have finished the work on the dev branch, and now we are on the master branch. For example:

The flowchart is as follows:

Switch back to the master branch, and then upload a readme.txt file, such:

You can see that the added line is missing. Because the commit is on the dev branch, but the master branch does not change. Now let's demonstrate how to merge branches.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • 4
  • Next Page

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.