背景
我正在与一个大型团队合作,使用git用于版本控制。正常流程是:
- 人们从“积压队列”中选择一张票。
- 通过当地分支机构(即
git checkout -b my_feature_branch
).
- 进行多次提交(即
git commit
).
- 将本地更改推送到远程分支以“备份”他们的工作,以便它可以驻留在多台计算机上,以防笔记本电脑损坏或被盗(即)
git push -u origin my_feature_branch
).
- Eventually creating a code review on our private github page, and doing a squashed merge from the feature branch to
master
.
除了员工根据需要创建的远程功能分支之外,我们还有几十个发布分支,用于创建我们交付给客户的“黄金版本”,即1.00
, 1.01
, 2.00
, 2.01
, 2.02
, etc.
Problem
Some developers have begun to complain that there are too many branches, and I tend to agree. Some developers haven't been diligent about cleaning up old branches when they are no longer needed (even though github provides a one-button delete feature for this once the code review is complete).
Question
Is there a way to configure our company github deployment so that, when people use git branch
via the CLI:
- 仅出现我们的“重要/发布/黄金”分支。
- 一次性开发人员(临时)分支仅通过以下方式出现
git branch -a
?
这样做的主要目标是减少混乱。
Edit: 我发现了类似的问题,但唯一的答案根本不适用(不要使用远程分支),这违反了我允许人们推送到远程分支作为数据备份形式的关键约束。的概念私有命名空间正如@Mort 所暗示的,似乎正是我正在寻找的。现在,我该如何实现呢?
长话短说:you can- 但这可能有点棘手。
您应该使用namespace
概念(看这里:git 命名空间)
引用文档:
Git 支持将单个存储库的 ref 划分为多个命名空间,每个命名空间都有自己的分支、标签和 HEAD。 Git 可以将每个名称空间公开为独立的存储库,以便从中提取和推送,同时共享对象存储
and
将多个存储库存储为单个存储库的命名空间可以避免存储相同对象的重复副本,例如在存储同一源的多个分支时。
要激活命名空间,您可以简单地:
导出 GIT_NAMESPACE=foo
or
git --namespace=foo 克隆/拉/推
当命名空间处于活动状态时,通过git remote show origin
您只能看到在当前命名空间中创建的远程分支。如果您停用它(unset GIT_NAMESPACE
),您将再次看到主要的远程分支。
根据您的情况,可能的工作流程可能是:
创建一个功能分支并对其进行处理
export GIT_NAMESPACE=foo
git checkout -b feature_branch
# ... do the work ...
git commit -a -m "Fixed my ticket from backlog"
git push origin feature_branch # (will push into the namespace and create the branch there)
合并上游
unset GIT_NAMESPACE
git checkout master
git pull (just to have the latest version)
git merge --squash --allow-unrelated-histories feature_branch
git commit -a -m "Merged feature from backlog"
git push # (will push into the main refs)
棘手的部分
命名空间提供了分支的完全隔离,但每次都需要激活和停用命名空间
注意
推的时候要注意。 Git 将推送当前名称空间。如果您在功能分支中工作并且忘记激活名称空间,则在推送时,您将在主参考中创建功能分支。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)