Use git Flow correctly

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

git best practices in the team-how to use git Flow correctly


We've been switching from SVN to git for years, and now almost all of the projects are managed using GitHub, and this article tells you why Git is used and how it's used correctly in your team.

Advantages of Git

There are many advantages to git, but here are just a few points that I think are very prominent.

    1. Because it is distributed, all local libraries contain all the contents of the remote library.
    2. Excellent branching model, branching and merging branches, machine convenience.
    3. Fast, in this time is the era of money, git because the code is local, to branch and merge branch machine fast, using an SVN can appreciate this advantage.

Interested, can go to look at the design of Git itself, the internal architecture embodies a lot of advantages, it is worthy of investment genius programmer Linus (the father of Linux) hand

Version Management challenges

Although there are such excellent version management tools, but we face version management, there are still very big challenges, we all know that we work in the same warehouse, then each other's code collaboration will inevitably bring many problems and challenges, as follows:

    1. How do I start a feature development without affecting other feature?
    2. Because it is easy to create new branches, branches more how to manage, long time, how to know what each branch is doing?
    3. Which branches have been merged back to the trunk?
    4. How to manage the release? How do I freeze feature when I start a release, and how can developers continue to develop new features when prepare release?
    5. Online code out of the bug, how to quickly repair? And the repaired code should be included in the developer's branch and the next release?

Most developers now use Git for three or even two branches, one for master, one for develop, and one for various branches based on develop. This is a small project on the scale of the time can still be supported, because many people do the project is only one release, but a lot of people, and a long project cycle will have a variety of problems.

Git Flow

Just as code requires code specification, code management also requires a clear process and specification

Vincent Driessen in order to solve this problem put forward a successful Git branching Model

Here's a flowchart for Git flow

You can't understand the diagram above? It's OK, it's not your fault, I think this picture itself a bit of a problem, this picture should turn left 90 degrees, we should be very understanding.

Common branches of Git flow
    • Production Branch

That is, the master branch that we often use, this branch has recently been released into the production environment Code, recently released release, this branch can only be merged from other branches, cannot be directly modified in this branch

    • Develop Branch

This branch is our main development branch, which contains all the code to be published to the next release, the main merge with other branches, such as the feature branch

    • Feature Branch

This branch is mainly used to develop a new function, once the development is complete, we merge back into the develop branch into the next release

    • Release Branch

When you need to publish a new release, we create a release branch based on the develop branch, and after the release is complete, we merge into the master and develop branches

    • Hotfix Branch

When we found a new bug in production, we needed to create a hotfix, and when we finished hotfix we merged back to the master and develop branches, so the hotfix changes would go to the next release

How Git Flow works on the initial branch

All commits on the master branch should be tagged

Feature Branch

Branch name feature/*

After the feature branch is done, it must be merged back into the develop branch, which will generally delete the feature branch after merging the branches, but we can also keep

Release Branch

Branch name release/*

The release branch is created based on the develop branch, and after the release, we can test the release branch, modify the bug, and so on. At the same time, other developers can build on the new feature (remember: do not merge new changes from the develop branch to the release branch once the release branch has been hit )

When releasing a release branch, merge release to Master and develop, and tag the release version number on the master branch, then delete the release branch.

Maintain Branch Hotfix

Branch name hotfix/*

The hotfix branch is created based on the master branch and needs to be merged back into the master and develop branches and a tag on master

Git Flow code sample

A. Creating a develop branch

push -u origin develop    

B. Start of new feature development

some-feature develop# Optionally, push branch to origin:git push -u origin some-feature    # 做一些改动    git statusgit add some-filegit commit 

C. Completion of feature

merge --no-ff some-featuregit push origin developgit branch -d some-feature# If you pushed branch to origin:git push origin --delete some-feature 

D. Start relase

release-0.1.0 develop# Optional: Bump version number, commit# Prepare release, commit

E. Completion of Release

merge --no-ff release-0.1.0git pushgit checkout developgit merge --no-ff release-0.1.0git pushgit branch -d release-0.1.0# If you pushed branch to origin:git push origin --delete release-0.1.0 git tag -a v0.1.0 mastergit push --tags

F. Start hotfix

git checkout -b hotfix-0.1.1 master    

G. Completion of Hotfix

merge --no-ff hotfix-0.1.1git pushgit checkout developgit merge --no-ff hotfix-0.1.1git pushgit branch -d hotfix-0.1.1git tag -a v0.1.1 mastergit push --tags
Git Flow Tools

In fact, when you understand the above process, you do not have to use the tool, but in fact, most of us command is not remember, the process is not remember ah, swollen do it?

There are always smart people who create good tools for everyone to use, and that's git flow script.

Installation
    • OS X

Brew Install Git-flow

    • Linux

Apt-get Install Git-flow

    • Windows

Wget-q-O---no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | Bash

Use
    • Initialize: git flow init

    • start new feature: git flow feature start myfeature

    • publish a feature (i.e. push to remote): git flow feature publish Myfeature

    • get publish feature: git flow feature pull Origin myfeature

    • complete a feature: git flow feature finish myfeature

    • start a release: git flow release start release [BASE]

    • Publish a release: git flow release publish release
    • Release Release: git flow release finish release
      Don't forget git push--tags

    • Start a hotfix: git Flow hotfix start VERSION [BASENAME]

    • release a hotfix: git Flow hotfix finish VERSION

Git Flow GUI

It says so much, I know someone else can not remember, then someone made a GUI tool, you just need to click on the next line, tools to help you do these things!!!

Sourcetree

When you initialize with Git-flow, basically you just need to click on the Git Flow menu to select Start feature, release or hotfix, then select the Git Flow menu again and click Done Action. I'm going to take a walk, and I can't believe it's easier than that.

Currently Sourcetree supports Mac, Windows, Linux.

How much money is such a good tool? FREE!!!!

Git flow for Visual Studio

The Gospel of the vast vs
Gitflow for Visual Studio

In the end I often get emails asking me, he wants to use Git, but the company still insists on using SVN and so on, ask me the most? My approach is to:

First: Show him this article.

Second: Immediately find me, join our company, my mailbox is [email protected] qq:353275476

Use git Flow correctly

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.