vfclists
vfclists

Reputation: 20251

How can a remote Git repository be configured for pushing to, no fetching or pulling?

How can a remote Git repository be configured for pushing to, no fetching or pulling?

I have a repository in a location where it is not connected to a project management system, and I want to link it to another location where the project manager (Gogs) is.

How can I configure the local working copy to only push to the Gogs location, but never to pull from it, i.e. to ensure that a git fetch or git pull never references it?

How the .git/config entry for such a remote look like?

Upvotes: 1

Views: 138

Answers (1)

Leon
Leon

Reputation: 32514

You can set a fake fetch 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}

Thus, the .git/config entry for such a remote will look like below:

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

The following bash function will do the job:

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

Example:

$ git_disable_pull_from_remote origin

Upvotes: 3

Related Questions