[英]How to have my local repo pull from master, not a deleted branch?
I have a local repo that was initially cloned from a branch (using git clone --single-branch
). 我有一个本地存储库,最初是从分支中克隆的(使用git clone --single-branch
)。 That branch was merged into master and then deleted. 该分支已合并到master,然后删除。
When I tried to switch to master in my local repo using git checkout master
, I got error: pathspec 'master' did not match any file(s) known to git.
当我尝试使用git checkout master
切换到本地存储库中的git checkout master
,出现error: pathspec 'master' did not match any file(s) known to git.
I had to do a git checkout -b master
instead, and then git status
said I am on branch master. 我不得不做一个git checkout -b master
,然后git status
说我在分支master上。
But when I do a git pull
, it is still pointing to the deleted branch because it prints out fatal: Couldn't find remote ref refs/heads/deleted-branch-name
. 但是,当我执行git pull
,它仍然指向已删除的分支,因为它打印出了fatal: Couldn't find remote ref refs/heads/deleted-branch-name
。
How do I remove any remaining references to the deleted branch, so that git pull
pulls from the master branch? 如何删除对已删除分支的所有剩余引用,以便git pull
从master分支中拉出?
When you clone a single branch, you only get that single branch, not master
. 克隆单个分支时,您只会获得该单个分支,而不会获得master
。 When you then execute git checkout -b master
, you are checking out to a branch you are creating on the fly. 然后,当您执行git checkout -b master
,您将签出到正在动态创建的分支。 That is, you create a local branch called master
and you checkout to that branch. 也就是说,您创建一个称为master
的本地分支,然后签出该分支。 Of course, that master
branch is not related to your remote master
. 当然,该master
分支与您的remote master
无关。 You could have used git fetch origin
to get all the branches of the repo. 您可能已经使用git fetch origin
获取了仓库的所有分支。 Example: 例:
git fetch origin
git checkout -b master # creates a new branch called master
git merge origin/master # merge the master branch from the repo into yours
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.