error: pathspec 'master' did not match any file(s) known to git
- 首先我們看一下分支情況:
git branch -a
複製程式碼
- 如果沒有看到你想要的分支,先獲取所有分支:
git fetch
複製程式碼
- 切換到遠端master分支:
git checkout origin/master
複製程式碼
提示如下:
Note: checking out 'origin/master'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 4beea49... Merge branch 'develop' into 'master'
複製程式碼
執行git branch
* (detached from origin/master)
複製程式碼
- 現在我們可以從當前的detached分支切換並新建分支,可以理解為即將新建立的分支是由當前detached 分支出來的(為了為後續做準備,此處新分支就叫做master):
git checkout -b master
複製程式碼
這時我們使用git pull會提示如下錯誤:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> master
複製程式碼
說明我們新建立的master分支還不能和遠端的master分支建立追蹤關係(雖然表面我們看似已經建立了master分支,但git不認為它和遠端的master有任何關係),當然,您可以按照上面提示那樣,通過git pull指定遠端的分支和本地的分支來進行更新,但此處我們使用提示中的第二種方式,建立本地分支和遠端分支的追蹤關係:
git branch -u origin/master master
複製程式碼
- 這時我們執行git pull來看看什麼反饋:
Already up-to-date.
複製程式碼