git pull失敗的問題

當git clone以後,直接git pull它會自動匹配一個正確的remote urlgit

是由於在config文件中配置瞭如下內容:服務器

1 [branch "master"]2     remote = origin3     merge = refs/heads/master

代表:fetch

1.git 處於master這個branch下時,默認的remote就是origin;this

2.當在master這個brach下使用指定remote和merge的git pull時,使用默認的remote和merge。url

 

可是對於本身建的項目,並用push到遠程服務器上,並無這塊內容,須要本身配置spa

若是直接運行git pull,會獲得如此結果:code

 

複製代碼

 1 $ git pull 2 Password: 3 You asked me to pull without telling me which branch you 4 want to merge with, and 'branch.master.merge' in 5 your configuration file does not tell me, either. Please 6 specify which branch you want to use on the command line and 7  try again (e.g. 'git pull <repository> <refspec>'). 8 See git-pull(1) for details. 9 10 If you often merge with the same branch, you may want to11 use something like the following in your configuration file:12 13     [branch "master"]14     remote = <nickname>15     merge = <remote-ref>16 17     [remote "<nickname>"]18     url = <url>19     fetch = <refspec>20 21 See git-config(1) for details.

複製代碼

在參考[2]中,有這樣一段:ci

Note: at this point your repository is not setup to merge _from_ the remote branch when you type 'git pull'. You can either freshly 'clone' the repository (see "Developer checkout" below), or configure your current repository this way:rem

1 git remote add -f origin login@git.sv.gnu.org:/srv/git/project.git2 git config branch.master.remote origin3 git config branch.master.merge refs/heads/master

 

所以經過git config進行以下配置:get

1   $ git config branch.master.remote origin2   $ git config branch.master.merge refs/heads/master

或者加上--global選項,對於所有項目都使用該配置。


執行完以上 命令,在config文件中配置瞭如下內容:

1 [branch "master"]2     remote = origin3     merge = refs/heads/master


============================

假如 當前 倉庫有 兩個 分支,master 和 test1,當咱們 執行了 如下 兩條命令以後:


git config branch.test1.remote origin

git config branch.test1.merge refs/heads/test1


將在 在config文件中配置瞭如下內容:

1 [branch "test1"]2     remote = origin3     merge = refs/heads/test1
相關文章
相關標籤/搜索