阅读 647

切换分支时:pathspec master did not match any file(s) known to git

error: pathspec 'master' did not match any file(s) known to git

  1. 首先我们看一下分支情况:
git branch -a
复制代码
  1. 如果没有看到你想要的分支,先获取所有分支:
git fetch
复制代码
  1. 切换到远程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)
复制代码
  1. 现在我们可以从当前的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
复制代码
  1. 这时我们执行git pull来看看什么反馈:
Already up-to-date.
复制代码
文章分类
开发工具
文章标签