简体   繁体   English

Git 分支最佳实践——master、production、staging?

[英]Git branch best practices - master, production, staging?

I'm trying to understand the purpose of the master branch.我试图了解 master 分支的目的。 Every new repo starts with one, I've worked several jobs where the master branch was never touched after the repo's initialization and production was the final branch that deployed to production.每个新的 repo 都从一个开始,我做过几项工作,在 repo 初始化后从未触及过 master 分支,而生产是部署到生产的最后一个分支。 eg例如

somefeature => qa => staging => production ==> deploy somefeature => qa => staging => 生产 ==> 部署

or even without a qa branch:甚至没有 QA 分支:

somefeature => staging (acting as qa) => production ==> deploy somefeature => staging(充当 qa)=> 生产 ==> 部署

Given that there are no hard rules, what is a reasonably common approach to branches, particularly staging, production and master?鉴于没有硬性规则,对于分支,特别是 staging、production 和 master,什么是合理常见的方法?

There are a variety of common branching approaches, and which one you use depends on your needs.有多种常见的分支方法,您使用哪一种取决于您的需要。

If you're running your own source code, you may be fine with a single main branch (such as master ).如果您正在运行自己的源代码,则可以使用单个主分支(例如master )。 In such a model, you create a PR and get all required approvals.在这样的 model 中,您创建一个 PR 并获得所有必需的批准。 You then deploy outside of your branching system using a separate deploy tool, such as a bot, and merge into the main branch when your code is stable.然后,您使用单独的部署工具(例如机器人)在分支系统之外进行部署,并在代码稳定时合并到主分支中。 GitHub uses this system. GitHub 使用该系统。

You may also wish to use a tiered branching model where a PR gets merged into a sequence of branches, first a development branch, then a QA branch, a staging branch, and a production branch.您可能还希望使用分层分支 model,其中 PR 合并到一系列分支中,首先是开发分支,然后是 QA 分支,暂存分支和生产分支。 The latter may or may not be called master .后者可能称为也可能不称为master

If you're working on a release-based project, you can have a single development branch into which most code merges and one or more release branches where fixes get cherry-picked if necessary.如果您正在处理基于发布的项目,您可以拥有一个大多数代码合并到其中的开发分支和一个或多个发布分支,如果需要,修复会在其中被挑选出来。 This is the model many open-source projects use, such as Git LFS.这是很多开源项目使用的model,比如Git LFS。 Git uses a similar strategy, but with additional branches where changes "cook" until they are considered stable. Git 使用类似的策略,但有额外的分支,其中更改“烹饪”直到它们被认为是稳定的。

There are other, more complicated workflows, such as Git Flow, which may or many not meet your needs.还有其他更复杂的工作流程,例如 Git Flow,它们可能或许多不能满足您的需求。 One thing to consider with a branching strategy is, if you have multiple branches, how you're going to get code through the stages.分支策略要考虑的一件事是,如果您有多个分支,您将如何通过各个阶段获取代码。 You may want to have a bot or tool that guides things through the stages after the initial PR or branch, since otherwise it's easy for things to get lost.您可能希望有一个机器人或工具来引导事情通过初始 PR 或分支之后的各个阶段,否则事情很容易迷失方向。

What's important is that you document your workflow clearly so everyone knows how it works and that you be willing to revisit your workflow if it doesn't meet your needs anymore.重要的是您清楚地记录您的工作流程,以便每个人都知道它是如何工作的,并且如果它不再满足您的需求,您愿意重新审视您的工作流程。 You may find that parts of your workflow other than your branching strategy may need to change if things aren't working for you, and it's okay to make those changes if that works better for your project or organization.您可能会发现,如果事情对您不起作用,您可能需要更改除分支策略之外的工作流部分,如果这对您的项目或组织更有效,则可以进行这些更改。

But overall, it's hard to make a one-size-fits-all recommendation.但总的来说,很难做出一刀切的推荐。

If you are not familiar with git-flow, that is a very reasonable branching strategy:如果你不熟悉 git-flow,这是一个非常合理的分支策略:

https://nvie.com/posts/a-successful-git-branching-model/ https://nvie.com/posts/a-successful-git-branching-model/

Regarding the master branch, keep in mind that "master" is simply the default name assigned to the first branch of a git repo.关于 master 分支,请记住,“master”只是分配给 git 存储库的第一个分支的默认名称。 Nothing more, nothing less.不多也不少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Git摆脱Master Branch中的Merge评论? - How to get rid of Merge Comments in the Master Branch with Git? 用于制作和登台的不同样式表 - Different style sheets for production and staging 将更新后的 master 分支推送到位于同一项目文件夹中并在本地 git repo 中配置的远程存储库 - Push the updated master branch to remote repository which in in same project folder and configured in local git repo 为firebase登台和生产数据库创建“蓝图”? - Creating “blueprints” for firebase staging and production databases? 在登台服务器中有效的URL无效,但在生产中失败 - Invalid URL that works in staging server but fails in production 根据环境(开发,登台,生产)进行角度配置 - Angular config according to environment (dev, staging, production) jQuery验证不适用于暂存和生产系统 - Jquery validation not working on staging and production systems 转译 JS 代码库的最佳实践:包含在 git 中还是在安装过程中生成? - Best practices with transpiled JS codebase: included in git or generated during installation process? AngularJS最佳实践 - 风格指南 - AngularJS best practices - Styleguide 反应过滤器最佳做法 - React filter best practices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM