[英]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? 如何配置远程Git存储库以进行推送,不进行提取或拉取?
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. 我在一个没有连接到项目管理系统的位置有一个存储库,我想将它链接到项目经理(Gogs)所在的另一个位置。
How can I configure the local working copy to only push to the Gogs location, but never to pull from it, ie to ensure that a git fetch
or git pull
never references it? 如何将本地工作副本配置为仅推送到Gogs位置,但永远不要从中拉出,即确保
git fetch
或git pull
从不引用它?
How the .git/config
entry for such a remote look like? 这样的遥控器的
.git/config
条目怎么样?
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: 因此,这种遥控器的
.git/config
条目如下所示:
[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: 以下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"
}
Example: 例:
$ git_disable_pull_from_remote origin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.