如何将远程Git存储库配置为“推到”,而不是“获取”或“拉取”?

如何将远程Git存储库配置为“推到”,而不是“获取”或“拉取”?,git,git-branch,Git,Git Branch,如何将远程Git存储库配置为“推到”,而不是“获取”或“拉取” 我在一个没有连接到项目管理系统的位置有一个存储库,我想将它链接到项目经理(Gogs)所在的另一个位置 如何将本地工作副本配置为仅推送到Gogs位置,而不从中提取,即确保git fetch或git pull从不引用它 这样一个远程设备的.git/config条目是什么样子的?您可以设置一个假获取URL: $ git remote set-url origin "https://{pulling-is-disabled-for-this

如何将远程Git存储库配置为“推到”,而不是“获取”或“拉取”

我在一个没有连接到项目管理系统的位置有一个存储库,我想将它链接到项目经理(Gogs)所在的另一个位置

如何将本地工作副本配置为仅推送到Gogs位置,而不从中提取,即确保
git fetch
git pull
从不引用它


这样一个远程设备的
.git/config
条目是什么样子的?

您可以设置一个假获取URL:

$ git remote set-url origin "https://{pulling-is-disabled-for-this-remote}"
$ # Below command is needed since git remote set-url sets both fetch and push URLs
$ git remote set-url --push origin CORRECT_REMOTE_URL
$ git pull origin
fatal: unable to access 'https://{pulling-is-disabled-for-this-remote}/': Could not resolve host: {pulling-is-disabled-for-this-remote}
因此,此类远程设备的
.git/config
条目如下所示:

[remote "origin"]
    url = https://{pulling-is-disabled-for-this-remote}
    pushurl = CORRECT-URL-MUST-BE-PUT-HERE

以下bash函数将完成此工作:

git_disable_pull_from_remote()
{
    if [ $# -ne 1 ];
    then
        echo 1>&2 "Usage: git_disable_pull_from_remote <remote_repo>"
        return 1
    fi

    local url="$(git remote get-url --push "$1")"
    git remote set-url "$1" "https://{pulling-is-disabled-for-this-remote}"
    git remote set-url --push "$1" "$url"
}

如果不添加
url
,即不使用
git-remote
命令直接在
.git/config'中创建远程,只使用
pushurl
而不添加
url
fetch
命令,那么直接在.git/config'中创建条目就足够了,ie不使用git remote
,或者在推送过程中会出现一些错误吗?
fetch
设置是否对
pushurl
仅远程有影响?@vfclists使用
git-remote
执行任务有什么问题?因为我不确定
git-remote
命令除了在
中添加我期望的最小更改之外,还有其他作用。git/config
我不认为
gitremote
还有其他副作用,但是如果您担心的话,那么我认为直接在
.git/config
中添加条目(尽管包括
url
pushurl
)应该可以。
$ git_disable_pull_from_remote origin