Git禁用从本地存储库推送

Joh*_*rum 11 git configuration clone

我有一个包含一些核心代码的存储库,并且我希望克隆它的每个客户端,所以每次客户端想要升级到最新功能时我都可以执行git pull.

为了不搞砸事情并进行只有一家公司看到的更改,有没有办法只允许在本地存储库中提取?我仍然希望能够从我的开发环境推送对核心存储库的更改,但不希望生产计算机能够推送.

Pau*_*ijs 15

在文件中的clone-source存储库(称为origin)的远程部分中指定不存在的pushurl.git/config.例:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = <url>
        pushurl = www.non-existing-url.com
Run Code Online (Sandbox Code Playgroud)

或者,如果您不喜欢编辑存储库的配置文件,可以键入:

$ git config remote.origin.pushurl www.non-existing.com
Run Code Online (Sandbox Code Playgroud)

推送时你会收到如下错误信息:

$ git push
fatal: 'www.non-existing-url.com' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

当然,您需要编辑每个克隆存储库的配置文件.


小智 5

我发现远程命令更有用,所以我不必直接搞乱配置.

git remote set-url --push origin www.non-existing-url.com
Run Code Online (Sandbox Code Playgroud)

也应该工作