我如何使用git裸存储库来推入非裸存储库? [英] How can I use a git bare repository to push into a non-bare repository?

查看:169
本文介绍了我如何使用git裸存储库来推入非裸存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想将所有本地更改推送到远程服务器上的备份裸存储库,然后让裸存储将更改推送到同一服务器上的生产(非裸)。现在,我正在考虑做一个钩子。如果有问题,我不会使用gitosis。我怎样才能达到这个目标?

我不知道这是否是正确的方式,但我基本上只是想将我的本地更改推送到备份回购(裸)和非裸回购。

解决方案

TL; DR



您无法成功推送到非裸仓库。



三个实用选项



选项1



实际上,如果您尝试足够努力,您可以 你做。例如,推送错误消息说:


您可以将'receive.denyCurrentBranch'配置变量设置为
'ignore'或在远程仓库中发出'警告',允许将当前分支推入
;然而,除非您安排
更新其工作树以匹配您以某种
以其他方式推送的内容,否则不建议这样做。


您必须在非裸露的远程设备上更改配置,并添加一个post-receive钩子来更新工作树。所以,当有更简单的方法去做时通常没什么用处。



选项2



您也可以在裸存储库上创建一个post-receive挂钩,它将使用ssh(或类似)连接到具有非裸存储库的远程主机,并在裸存储库更新。这与前一个选项非常相似,但不需要在非裸存储库上进行任何配置更改。



选项3



轮询是另一种选择。您可以执行与 https://stackoverflow.com/a/11254771/1301972 类似的操作,您可以在其中投票裸仓库可以定时进行拉取。此选项根本不需要git配置或自定义挂钩,因此,如果您有权访问crontab,那么这就是我推荐的通用解决方案。


Basically, I want to push all my local changes to a backup bare repository on a remote server and then have the bare repositiory push the changes to production (non-bare) on the same server. Right now, I'm thinking of doing a hook. I'm not using gitosis if that matters. How can I achieve this goal?

I don't know if this is the RIGHT way, but I basically just want to push my local changes to a backup repo (bare) and a non-bare repo.

解决方案

TL;DR

You can't successfully push to a non-bare repository.

Three Practical Options

Option 1

Actually, you can push a non-bare repository if you try hard enough, but it won't update your working tree for you even if you do. For example, the push error message says:

You can set 'receive.denyCurrentBranch' configuration variable to 'ignore' or 'warn' in the remote repository to allow pushing into its current branch; however, this is not recommended unless you arranged to update its work tree to match what you pushed in some other way.

You'd have to change the configuration on the non-bare remote, and add a post-receive hook to update the working tree. So, it's generally not useful to do it when there are easier ways to go about it.

Option 2

You could also create a post-receive hook on your bare repository that would use ssh (or similar) to connect to the remote host with the non-bare repository and do a pull whenever the bare repository is updated. This is pretty similar to the previous option, but doesn't require any configuration changes on the non-bare repository.

Option 3

Polling is another option. You could do something similar to https://stackoverflow.com/a/11254771/1301972, where you're polling your bare repository for a pull at timed intervals. This option requires no git configuration or custom hooks at all, so that's what I'd recommend as a general solution if you have access to a crontab.

这篇关于我如何使用git裸存储库来推入非裸存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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