what should the master branch contain in git

被刻印的时光 ゝ 提交于 2019-12-09 17:48:03

问题


I have read about multiple different git branching strategies and I was suprized that the master branch was often used as a 'production-ready' branch and there would be an additional uat and dev branch. I'm thinking to set up our git repository with the same 3 branches, but to let 'master' contain the dev code and add a production and uat branch. That way, developers can simply merge to the default git branch (being 'master'). Is there a reason not to do it like that?

gr,

Coen


回答1:


There is no specific reason not to pick one workflow over another, with Git it's usually left to the discretion of the development team to decide their best practice.

The production-ready master approach you mentioned often has more than one dev branch (sometimes called feature branches), master is then chosen as the final place to put all these since there should typically be only one master branch (and often only one production build).

This is how many companies work, but certainly not all. Many others use an "unstable master" approach, which follows a similar pattern to the one you mention - some instead have a production repository, their own master and branches are considered unstable, and the team leader pushes to the production repo when code in a particular branch is considered production ready.

The key aspect in Git here is that everyone has their own local repository, with their own branches and master. This allows them to create their own private branches any time they want, for whatever evil purposes they see fit, but it does make defining the purpose of branch names more difficult to enforce.




回答2:


The key concept to understand with a DVCS (Distributed Version control System) is that you don't have one workflow (merges between branches), but two: publication (push/pull) between repositories.
See "What git branching models actually work?"

That means you will clone repositories around, and for each clone, what you want to ask is:

If I clone a repo "by default" (no special parameters), what content do I want to see?

That content, out of all the possible branches contained by the cloned repo, will be your 'master' branch.
And you can change that "branch by default": see "Git: Correct way to change Active Branch in a bare repository?".

So if you have a repo dedicated for development, the master branch will represents the latest code "that work", with other branches for various "experiments" in progress.
That is basically what the Git repo itself follows: See "Git/Git Workflow".

But any other clone can be dedicated for other development life-cycle step (uat -- user acceptance test, sit -- system integration test, -- pre-prod or prod).
In that case, their 'master' branch will have a different meaning, adapted to the role played by that repo.




回答3:


I think a good starting place for this is to actually read Git's recomended workflow document. They talk about using master as stable, and feature branches.

An excerpt:

Graduation ~~~~~~~~~~

As a given feature goes from experimental to stable, it also "graduates" between the corresponding branches of the software. git.git uses the following 'integration branches':

  • 'maint' tracks the commits that should go into the next "maintenance release", i.e., update of the last released stable version;

  • 'master' tracks the commits that should go into the next release;

  • 'next' is intended as a testing branch for topics being tested for stability for master.

There is a fourth official branch that is used slightly differently:

  • 'pu' (proposed updates) is an integration branch for things that are not quite ready for inclusion yet (see "Integration Branches" below).

Each of the four branches is usually a direct descendant of the one above it.

Conceptually, the feature enters at an unstable branch (usually 'next' or 'pu'), and "graduates" to 'master' for the next release once it is considered stable enough.




回答4:


It all depends on the comfort of the developers. You can go ahead with the approach what you explained. Also there can be multiple branches for making the commits based on sprints or any other methodology. Every time you are about to deploy the code in production, merge the specific branches on which the commits have been pushed and way to go .



来源:https://stackoverflow.com/questions/10397427/what-should-the-master-branch-contain-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!