2017-05-06 92 views
1

遠程Git存儲庫如何配置爲推送,不提取或拉動?遠程Git存儲庫如何配置爲推送,不提取或提取?

我有一個存儲庫,它沒有連接到項目管理系統,我想將它連接到項目經理(Gogs)的另一個位置。

如何將本地工作副本配置爲僅推送到Gogs位置,但從不拉取它,即確保git fetchgit pull從不引用它?

.git/config這樣的遠程入口怎麼樣?

回答

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 
+0

應該在'的.git /配置」與僅'pushurl'而不添加'url',即不使用'GIT中remote'命令完成同樣的事情創建遠程直接? – vfclists

+0

直接在'.git/config'中創建一個條目,只需要'pushurl'而不需要添加'url'和'fetch'就足夠了,即不使用'git remote',或者在推動過程中會冒一些錯誤? 'fetch'設置對'pushurl'只有遠程有效嗎? – vfclists

+0

@vfclists對於任務使用'git remote'有什麼問題? – Leon

相關問題