"Translating" How to use Git efficiently

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

Original link

The code went well yesterday and it's not going to work today.

The code was deleted.

Suddenly there was a strange bug, but no one knew what was going on.

If you have ever seen any of the above, then this article is intended for you.

In addition to knowing, git add git commit There are other important techniques that need to git push be mastered in Git. It's helpful to us in the long run. Here I'm going to show you Git best practices.

Git Workflow

When multiple developers are involved with a project, it is necessary to use the Git workflow correctly.

Here I will describe a workflow that will be very useful in a large multi-person project.

Objective

Suddenly one day, you become a technical Leader of a project and plan to make the next Facebook. In this project you have three developers.

    1. Alice: A small white development.
    2. Bob: Have one year of work experience to understand basic development.
    3. John: Three years of development experience, skilled in developing skills.
    4. You: The technical head of the project.
Git Development Process Master Branch
    1. The Master branch should always remain consistent with the production environment.
    2. Since master and Production code are consistent, no one, including the technical owner, can develop directly on master.
    3. The real development code should be written on the other branches.
Release (release) branch
    1. When the project starts, the first thing to do is create a publishing branch. The publishing branch is created based on the master branch.
    2. All code related to this project is in the publishing branch, which is also a release/ common branch with the beginning.
    3. For example, this time the release branch is called release/fb .
    4. There may be multiple projects running based on the same code, so you need to create a separate publishing branch for each project. Assuming there is another project running in parallel, it is necessary to create a separate publishing branch for this project, for example release/messenger .
    5. A separate publishing branch is required because multiple parallel projects are run based on the same code, but there is no conflict between the projects.
Feature (function Branch) branch
    1. For each feature in the app, you should create a separate branch of functionality that ensures that these features can be built separately.
    2. The branch of functionality is just like the other branches, only the feature/ beginning.
    3. Now, as a technical Leader, you ask Alice to do the Facebook login page. So he created a new branch of functionality. To name him feature/login . Alice will write all the login codes on this branch.
    4. This feature branch is usually created based on the release branch.
    5. Bob's task is to create the Add Friends page, so he creates a feature/friendrequest feature branch called.
    6. John is scheduled to build the message flow, so a feature/newsfeed feature branch is created.
    7. All developers are developing on their own branches, so far it's normal.
    8. Now when Alice has completed his login development, he needs to send his feature branch to the release feature/login branch. This process is accomplished by initiating one pull request .
Pull Request

First of all, pull request you can't get confused git pull .

Developers cannot push code directly to the release (release) branch, and technical Leader need to do a code review before the feature branch is merged into the release branch. This is also pull request done by the.

Alice can submit it as follows on GitHub pull request .

There is a "New pull request" button next to the name of the branch, which will display the following screen:

    • The Compare branch is the functional branch of Alice feature/login .
    • The base branch should be the publishing branch release/fb .

After clicking, Alice needs to pull request enter a name and description for this, and then click on the "Create pull Request" button.

At the same time Alice needs to pull request specify a reviewer for this. As a technical Leader you have been chosen as the reviewer of this time pull request .

After you complete the code review, you need to merge this feature branch into the release branch.

Now that you have feature/login merged the branch release/fb , and Alice is very happy that his code has been merged.

Code conflicts
    1. Bob completes his coding work and initiates one for the release/fb branch pull request .
    2. The code conflict occurs because the publishing branch has merged the login code. Resolving conflicts and merging code is the responsibility of reviewer. In such a case, the conflict and merge code will need to be resolved as a technical Leader.
    3. Now John has also completed his development and wants to merge the code into the publishing branch. But John is very good at resolving code conflicts. He release/fb merges the latest code into his own branch of functionality feature/newsfeed (via the git pull or git merge command). At the same time he solves all the conflicts that exist, and now has feature/newsfeed all the code to publish the branch release/fb .
    4. At last John created one pull request , because John had solved all the problems, so this time pull request there will be no more conflict.

So there are usually two ways to resolve code conflicts:

    • pull requestThe reviewer needs to resolve all code conflicts.
    • Developers need to make sure that the latest code for the publishing branch is merged into a feature branch and that all conflicts are resolved.
or the Master branch

Once the project is complete, the code that publishes the branch needs to be merged back into the master branch and published to the production environment.

Therefore, the code in the production environment is always consistent with the master branch. And for any future project, make sure the master code is up to date.

Our team is developing in this way, and it is true that we can reduce the problem of code management as much as possible.

Off Topic

Like the previous article, how to become a "not so bad" programmer, it is suggested that we all look at foreign high-quality blog.

Even try to communicate with the author, through communication The original author will also paste my translation link in the original text. Everyone's mutual benefit makes good articles broadcast more widely.

Your point of praise and forwarding is the biggest support.

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.