如何为多个网站做分支方法? [英] How to do branching approach for multiple sites?

查看:236
本文介绍了如何为多个网站做分支方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,想知道这种分支方法对我们打算做的事情是否合适。



我们有三个站点




  • prod.websitename.com - 活网站

  • sandbox.websitename.com - 测试网站由我们的客户使用

  • dev.websitename.com - 内部网站用于在推送到活动网站前开发和测试修补程序/功能


我们打算做的是拥有一个集中的存储库,可以为所有三个站点提供服务。版本库将有三个分支:master,sandbox和development。然后,我们只需检出分支来更改文件并为每个站点提取/推送更改。

对于更改,开发将推送到主站和沙箱分支。沙盒永远不会被推到主人身边。



这样好吗?任何意见,高度赞赏。



非常感谢。

解决方案

它可以工作,只要您的主单个回购是可以推送的裸回购



从那里开始,收到后挂钩可触发相关结帐,具体取决于已推送的分支(请参阅编写git post-receive hook来处理特定分支

 #!/ bin / bash 
while readre oldrev newrev refname
do
branch = $(git rev-parse --symbolic --abbrev-ref $ refname)
if [master==$ branch];然后
#做某事
fi
if [sandbox==$ branch];然后
#做某事
fi
if [development==$ branch];然后
#做某事
fi
完成




对于更改,开发将推到主控和沙箱分支。


这不是最佳做法:您应该从 dev 添加到 master 沙箱 local 然后将这些分支推送到独特的远程仓库。

定期重新装仓 dev master 也是一个好主意。


I'm new to git and would want to know if this branching approach would be okay for what we intended to do.

We'll have three sites

  • prod.websitename.com - live site
  • sandbox.websitename.com - testing site that can be used by our clients
  • dev.websitename.com - internal site for developing and testing hotfix/features before pushing to live site

What we intend to do is to have a single centralized repository that would serve all three sites. The repository will have three branches: master, sandbox, and development

and then we'll just checkout the branch to change files and pull/push the changes for each site.

For changes, development will be pushed to both master and sandbox branch. Sandbox will never be pushed to master.

Is this okay? Any advice is highly appreciated.

Thank you so much.

解决方案

It can work, provided your main single repo is a bare repo to which you can push.

From there, a post-receive hook can trigger the relevant checkout, depending on the branch which has been pushed (see "Writing a git post-receive hook to deal with a specific branch")

#!/bin/bash
while read oldrev newrev refname
do
    branch=$(git rev-parse --symbolic --abbrev-ref $refname)
    if [ "master" == "$branch" ]; then
        # Do something
    fi
    if [ "sandbox" == "$branch" ]; then
        # Do something
    fi
    if [ "development" == "$branch" ]; then
        # Do something
    fi
done

For changes, development will be pushed to both master and sandbox branch. Sandbox will never be pushed to master.

That is not the best practice: you should merge what you need from dev to the master and sandbox local branches, and then push those branches to the unique remote repo.
Regularly rebasing dev on top of master is also a good idea.

这篇关于如何为多个网站做分支方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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