Wednesday, June 24, 2020

4 types of git branches

If you have worked as software engineer in cooperate environment, you should have already familiar with develop branch and master branch. Svn merge strategy is slightly different from git strategy, but they are quite similar. In git, the branch names are arbitrary, we can name branch whatever we like, and all the branch names are equal. However industry adopted some conventions. Usually we have a branch named develop, which is from master branch. All the developers contribute to this branch. From this branch, test releases are often created, which are the temporary packages deployed to the QA servers.

Once the develop branch is tested and stable, software developers or release engineers will merge the develop branch to the master branch. The master branch is usually used to create the package that will be released to production and deployed on the production servers.

Besides the develop branch and master branch, we usually encounter other 4 types of repository branches.

1. Bugfix branches are typically used for fixing bugs against a release branch. Conventionally these branches are prefixed with bugfix/
2. Feature branches are typically from and merged back into the development branch, they often used for specific feature work. Conventionally these branches are prefixed with feature/.

Bugfix branches and feature branches are where developers check in code, create pull request, check in code review updates. This is a safe branch to experiment. Any mistake only effect this particular branch, won't effect other developers working on other branches. The bugfix and feature only start to effect other developers after they are merged to the development. Sometimes, more than one developers updated the same line of the develop branch in their bugfix or feature branches, there will be merge conflict. The developer merge his/her branch earlier won't have problem, the developer merges his/her branch later will get merge conflict at the time of command "git push". 

The solution is to 
  • git checkout develop
  • git pull
  • git checkout bugfix/bugfixbranchname
  • git pull
  • git merge develop
At this point, the merge will fail, but the failure message will list all the files with conflict.
Go the files and manually fix the conflict lines, the 
  • git commit -am "solve conflict"
  • git push

3. Hotfix branches are typically used to quickly fix the production branch. They conventionally are prefixed with hotfix/. Hotfix often goes the fast path in emergency situations, they often directly from the master branch, and merge back to master branch. Then these changes are applied back to the development branch.

4. Release branches are typically branches from the develop branch and changes are merged back into the develop branch, they are used for release tasks and long-term maintenance. Some company use master branch as the release branch, then use tags to differentiate different releases. Some companies has multiple release branches names other than master. They conventionally are prefixed with release/.


No comments:

Post a Comment

meta.ai impression

Meta.ai is released by meta yesterday, it is super fast you can generate image while typing! You can ask meta.ai to draw a cat with curvy fu...