如何保持git仓库的公共和私人版本同步? [英] How to keep public and private versions of a git repo in sync?

查看:211
本文介绍了如何保持git仓库的公共和私人版本同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Github发布了一个开源的Rails应用程序(可能是MIT许可证)。我还想维护我们将用作付费服务一部分的项目的私人分支/分支。

在这种情况下组织回购的最佳方式是什么?而且,当我有更新应该同时进行时,我如何保持项目同步? 解决方案最简单的解决方案是在私人存储库中有私人分支这只是将 不推送 到公共存储库。

为此,您可能需要在config中指定要推送到公共存储库的所有分支(而不是使用通配符镜像refspec + refs / *:refs / * ),或仔细推送您想要发布的分支,并依靠推送匹配分支(远程存在的分支)的Git行为将push.default设置为当前默认值值匹配。



如果您偶然推送您的私人分支,您可以使用git push<将其在远程存储库中删除(除非配置为禁止此操作) ; remote >:refs / heads /< private-branch > (要记住这一点:将空值推送到远程分支)。您可以使用远端的挂钩来防止意外推送您的私人分支,请参阅 update-偏执狂示例钩子在contrib / examples。






旁注: Junio C Hamano ,git维护者,只向指定的分支集推送公共git存储库:'maint','master','next','pu'(提议的更新)和'html','man','todo';他不会发布经常变更的功能分支。

SETUP:

 
正在运行的存储库---->私有存储库(裸)---->公共存储库
\- -----私人------- / \ -------保护------------ / \ ------- public --- - /

工作存储库 是工作区的存储库,你在提交,提交更改并解决冲突的地方进行提交;资料库在哪里做你的工作。假设它包含以下分支:公开,其中包含可以发布到世界的更改,私人,您不想与其他人共享或只与选定的子集共享,也可能是某些功能分支,如 234'或'add-frobnicator',即使被选中的组也没有准备好。这个存储库是非公开的,因为它没有发布。



它将有如下配置推送到'私人'存储库。请注意,匹配分支行为在这里明确设置,请参阅 git-pull manpage:

  [remoteprivate] 
url = user@example.com:/srv/private/git/repo.git
push = +:

私有存储库 是仅供选定人员使用的公共裸存储库,例如它仅可通过SSH获取。它只有准备好的分支,即'公共'和'私人'分支;这些分支在创建私有存储库时都存在,或者被工作存储库明确推送(git push private < branch> )。从工作存储库推送只传输(转移)只匹配分支,即只有'公共'和'私人'分支。
$ b 私人存储库具有 post-update post-receive 只将public分支推入public repository的钩子集(如果它被推送到它(当然,它可以无条件推送)。



公共存储库 是所有人都可以访问的公共裸存储库,例如它托管在GitHub和/或Gitorious和/或repo.or.cz上,或者可能通过 git:// 使用git-daemon的协议。它只包含'public'分支,它使用 update pre-receive 来接受分支的whilelist(这里只接受公共分支),或拒绝分支黑名单(在本例中,推送/创建'私人'分支将被拒绝)。它会在推送到私人存储库时自动更新。



这个设置可能过于复杂,您的情况可能不需要私人存储库。在这种情况下,working repository中用于直接推送到公共存储库的配置将如下所示:

  [repository' public] 
url = ssh://example.com/srv/git/repo.git
push = refs / heads / public:refs / heads / public

我希望这个例子能够帮助;请阅读文档,不要盲目使用它。


I'm releasing an open-source Rails app on Github (probably MIT license). I also want to maintain a private branch/fork of the project that we will use as part of a pay service.

What is the best way to organize the repo(s) in this scenario? And, how can I keep the projects in sync when I have updates that should go to both?

解决方案

The simplest solution would be to have private branch in your 'private' repository, i.e. branch which is simply not pushed to public repository.

For that you would probably need to either specify all branches you want to push to public repository in config (instead of using globbing mirroring refspec +refs/*:refs/*), or push carefully branches you want to publish and rely on Git behaviour of pushing matching branches (those which are present on remote side) setting "push.default" to current default value "matching".

If you by accident push your private branch, you can delete it in remote repository (unless it is configured to forbid this) using "git push <remote> :refs/heads/<private-branch>" (to remember this: push empty value to remote branch). You can protect against accidental pushing of your private branch using hooks on remote side, see e.g. update-paranoid example hook in contrib/examples.


Sidenote: Junio C Hamano, git maintainer, pushes to public git repositories only specified set of branches: 'maint', 'master', 'next', 'pu' (proposed updates), and 'html', 'man', 'todo'; he does not publish short-lived often changing feature branches.



EXAMPLE SETUP:

    working repository  ---->  private repository (bare)  ---->  public repository  
    \------ private -------/     \------- protected ------------/     \------- public -----/

"Working repository" is the repository with working area that you make commits in, where you pull changes and resolve conflicts; repository where you do your work. Let's say it contains the following branches: 'public' with changes that can be published to the world, 'private' that you want to not share with others or share only with selected subset of people, and perhaps some feature branches like 'ticket-234' or 'add-frobnicator', which are not ready even for selected group to see. This repository is non-bare, as it not published.

It would have something like the following configuration for pushing to 'private' repository. Note that "matching branches" behavior is set explicitely here, see git-pull manpage:

[remote "private"]
        url = user@example.com:/srv/private/git/repo.git
        push = +:

"Private repository" is public bare repository available only to selected people, for example it is available for fetching only via SSH. It has only branches which are ready, i.e. 'public' and 'private' branches; either those branches were present when creating "private" repository, or were pushed explicitely ("git push private <branch>") from "working" repository. Push from "working" repository pushes (transfers) only matching branches, i.e. only 'public' and 'private' branches.

"Private repository" has post-update or post-receive hook set which pushes 'public' branch only to "public repository" (see below) if it was pushed to it (well, it can push unconditionally).

"Public repository" is public bare repository available to everyone, for example it is hosted on GitHub, and/or Gitorious, and/or repo.or.cz, or perhaps it is served via git:// protocol using git-daemon. It contains only 'public' branch, and it uses update or pre-receive either to accept whilelist of branches (here only 'public' branch is accepted), or reject blacklist of branches (in this example pushes to/creating 'private' branch would be rejected). It is updated automatically when pushing to "private" repository.

This setup might be overly complicated for your needs; "private" repository might be not necessary in your case. In such case the configuration in "working repository" for pushing directly to "public repository" would look like this:

[repository "public"]
        url = ssh://example.com/srv/git/repo.git
        push = refs/heads/public:refs/heads/public

I hope this example would help; please however read the documentation and do not use it blindly.

这篇关于如何保持git仓库的公共和私人版本同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆