一个远程Git仓库如何配置为推送,不提取或拉动? [英] How can a remote Git repository be configured for pushing to, no fetching or pulling?
问题描述
远程Git仓库如何配置为推送,不提取或拉动?
我有一个仓库,它没有连接到项目管理系统,我想将它链接到项目经理(Gogs)所在的另一个位置。
如何配置本地工作副本以仅推送到Gogs位置,但从来没有从它拉,即确保 git fetch
或 git pull
永远不会引用它?
<.git / config 您可以设置一个假的抓取网址:
$ git远程设置网址来源https:// {正在禁止为此远程}}
$#因为git remote set-url同时设置提取和推送URL
,所以需要下面的命令$ git remote set-url --push origin CORRECT_REMOTE_URL
$ git pull origin
致命:无法访问'https:// {正在禁用is-remote} /':无法解析主机:{正在禁用此远程服务}
因此,这样一个远程的 .git / config
条目如下所示:
[remoteorigin]
url = https:// {拉不能用于此远程}
pushurl = CORRECT-URL-MUST-BE -PUT-HERE
以下bash函数将会执行工作:
git_disable_pull_from_remote()
{
if [$#-ne 1];
然后
echo 1>& 2用法:git_disable_pull_from_remote< remote_repo>
return 1
fi
local url =$(git remote get-url --push$ 1)
git remote set-url$ 1 https:// {正在禁用此远程服务}
git remote set-url --push$ 1$ url
}
示例:
$ git_disable_pull_from_remote原产地
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
orgit pull
never references it?How the
.git/config
entry for such a remote look like?解决方案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
这篇关于一个远程Git仓库如何配置为推送,不提取或拉动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!