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. Because it is distributed, all local libraries contain all the contents of the remote library. Excellent branching model, branching and merging branches, machine convenience. 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, you can look at the design of Git itself, the internal architecture embodies a lot of advantages, it is worthy of funding genius programmer Linus (the father of Linux) hand version Management challenges
Although there are such excellent version management tools, but when 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: How to start a feature development, without affecting the other feature. Because it is easy to create new branches, branches more how to manage, a long time, how to know what each branch is doing. Which branches have been merged back to the trunk. How to manage the release. How to freeze feature at the beginning of a release, how to prepare release, developers can continue to develop new features. The code on the line has a bug and how to fix it quickly. 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 picture 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 to the production environment Code, recently released release, this branch can only be merged from other branches, cannot directly modify the Develop branch in this 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 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 when we complete release we merge into the master and Develop branch hotfix branch
When we found a new bug in production, we needed to create a hotfix, complete hotfix, we merged back to the master and develop branch, so the change of hotfix will go to the next release Git flow how to work 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
git branch develop
git push-u origin Develop
B. Start of new feature development
git checkout-b some-feature Develop
# Optionally, push branch to Origin:
Git push-u Origin some-feature
# do a Some changes
git status
git add some-file
git commit
C. Completion of feature
Git pull origin develop
git checkout develop
git merge--no-ff some-feature
Git push origin develop
git BR anch-d some-feature
# If you pushed branch to Origin:
Git push Origin--delete some-feature
D. Start relase
git checkout-b release-0.1.0 Develop
# optional:bump version number, commit
# Prepare release, Commit
E. Completion of Release
git checkout master
git merge--no-ff release-0.1.0
git push
git checkout develop
git merge--no-ff re lease-0.1.0
git push
git branch-d release-0.1.0
# If you pushed branch to Origin:
Git push Origin--d Elete release-0.1.0
git tag-a v0.1.0 master
git push--tags
F. Start hotfix
git checkout-b hotfix-0.1.1 Master
G. Completion of Hotfix
git checkout master
git merge--no-ff hotfix-0.1.1
git push
git checkout develop
git merge--no-ff hotfix -0.1.1
git push
git branch-d hotfix-0.1.1
git tag-a v0.1.1 master
git 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 many of the commands just can't 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 usage
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
So many of the above, 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.
Such a good tool how much money? 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, etc., ask me the most. My approach is to:
First: Show him this article.
Second: Immediately find me, join our company, my mailbox is wangdeshui@outlook.com qq:353275476 Author: Wang Water
Source: Http://www.cnblogs.com/cnblogsfans
Copyright: The copyright of this article is owned by the author and must be reproduced by the author.