简体   繁体   English

在git中的远程存储库上创建专用分支

[英]Create private branch on remote repository in git

I would like to build specific flow on our company git. 我想在我们公司的git上构建特定的流程。

  1. developer create a branch on his local machine and commit there some files. 开发人员在他的本地机器上创建一个分支并提交一些文件。
  2. dev push this branch to remote repo dev将此分支推送到远程仓库
  3. Other devs cannot access to this branch 其他开发人员无法访问此分支
  4. after few rounds off pushing dev decide to publish his changes. 经过几轮推动开发人员决定公布他的变化。
  5. merge his private branch into public branch 将他的私人分支合并到公共分支
  6. push that public branch. 推动那个公共分支。

In the other words - is it possible to configure private remote branch in public repository? 换句话说 - 是否可以在公共存储库中配置私有远程分支?

The flow that is used in my team is to have complete separate repositories for each team member in addition to origin on the main git server. 我团队中使用的流程是除了主git服务器上的源之外,还为每个团队成员提供完整的单独存储库。

  1. Dev creates local branch on local machine and commits away Dev在本地机器上创建本地分支并提交
  2. At the end of the day (or whenever is suitable) dev pushes to his private repo git push jdoe-private my-cool-branch 在一天结束时(或适当的时候)dev推送到他的私人仓库git push jdoe-private my-cool-branch
  3. Dev decides he is happy for the work to be published and possibly merged so can tidy it up and rebase it with impunity Dev决定他很高兴发布并可能合并的作品,因此可以整理它并且不受惩罚地改变它
  4. Dev pushes his branch to origin git push origin my-cool-branch Dev推动他的分支到原点git push origin my-cool-branch

The rationale for this setup for us is to allow devs to freely rebase and avoid the problems that can arise from upstream rebasing and also to have full backups. 对我们来说,这种设置的基本原理是允许开发人员自由地改变并避免上游变基引起的问题以及完全备份。 The separate repositories are only private by convention but would be easy to add access control if required. 单独的存储库仅按惯例私有,但如果需要,可以很容易地添加访问控制。 There is a lot of duplication of data but unless your repo is really huge, this is probably not a concern. 有很多重复的数据,但除非你的回购真的很大,这可能不是一个问题。

The common solution I know is to agree on "branch namespaces", by prepending some string to branch names. 我所知道的常见解决方案是通过将一些字符串添加到分支名称来同意“分支命名空间”。 For example, branches that start with "private/" are for private experiments. 例如,以“private /”开头的分支用于私人实验。 You'd then get branches like 然后你会得到分支

  • private/JohnDoe/refactoring-taxcalculation 民营/ JOHNDOE /重构,taxcalculation
  • private/JohnDoe/newGUILayout 民营/ JOHNDOE / newGUILayout
  • private/JaneJones/Java8 民营/ JaneJones / Java8
  • private/TKirk/build-spaceship 民营/ TKirk /建造太空飞船

That keeps the branches separate, and makes it clear what their purpose is. 这使分支保持分离,并清楚地表明它们的目的是什么。 However, that way the branches are still public, because anyone can see and pull them. 但是,分支仍然是公开的,因为任何人都可以看到并拉动它们。

If you want to restrict access to these branches based on user, you'd need to have some kind of branch-based access control. 如果要根据用户限制对这些分支的访问,则需要使用某种基于分支的访问控制。 There is no such thing in core git, but some git hosting servers allow this (Atlassian Stash for example). 在核心git中没有这样的东西,但是一些git托管服务器允许这个(例如Atlassian Stash)。 I don't know of any server that allows these kind of private branches, but maybe there is one that allows it or lets you script a solution. 我不知道任何允许这种私有分支的服务器,但也许有一个允许它或让你编写解决方案的脚本。

Note, however, that what you are asking for is rather unusual. 但请注意,您要求的是相当不寻常的。 The common solution is the one I outlined above. 常见的解决方案是我上面概述的解决方案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM