简体   繁体   English

git禁用从本地存储库推送

[英]Git disable pushing from local repository

I have a repository with some core code in it, and for each client I wish to clone it so I can do git pull everytime a client wants to upgrade to the newest functionality. 我有一个包含一些核心代码的存储库,对于每个客户端,我都希望对其进行克隆,以便每次客户端想要升级到最新功能时都可以执行git pull。

In the interest of not screwing things up and making changes that only one company sees, is there a way to only allow fetches on a local repository basis? 为了不弄乱事情并进行只有一家公司才能看到的更改,是否有办法只允许在本地存储库中进行获取? I still want to be able to push changes to the core repo from my dev environment, but don't want production machines to be able to push. 我仍然希望能够从我的开发环境中将更改推送到核心仓库,但不希望生产机器能够推送。

Specify a non-existing pushurl in the remote section of the clone-source repository (called origin) in the file .git/config . .git/config文件的克隆源存储库的远程部分(称为origin)中指定一个不存在的pushurl Example: 例:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = <url>
        pushurl = www.non-existing-url.com

Or if you don't like editing the config file of the repository you can type: 或者,如果您不喜欢编辑存储库的配置文件,则可以键入:

$ git config remote.origin.pushurl www.non-existing.com

When pushing you'll get an error message like: 推送时,您会收到以下错误消息:

$ git push
fatal: 'www.non-existing-url.com' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

Of course you'll need to edit the config file of each cloned repository. 当然,您需要编辑每个克隆存储库的配置文件。

I find the remote command more useful so I don't have to mess with configs directly. 我发现远程命令更有用,所以我不必直接搞乱配置。

git remote set-url --push origin www.non-existing-url.com

should work as well 应该也可以

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

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