如何配置远程Git存储库以进行推送,不进行提取或拉取?

时间:2017-05-06 11:12:44

标签: git git-branch

如何配置远程Git存储库以进行推送,不进行提取或拉取?

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

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

这种遥控器的.git/config条目如何显示?

1 个答案:

答案 0 :(得分:3)

您可以设置虚假提取网址:

$ 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"
}

示例:

$ git_disable_pull_from_remote origin