简体   繁体   English

如何从本地主机(而不是已删除的分支)中提取本地存储库?

[英]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.

相关问题 无法将主分支从源拉入本地(已修改)存储库 - Unable to pull master branch from origin into local (modified) repo 在创建新分支后也需要从master到本地本地仓库的git pull安全吗?我也需要在该分支上查看最新更改? - Is it safe to do a git pull from master to my local repo after creating a new branch on which I need to see the latest changes too? 如何从git中删除从远程仓库中删除和忽略的本地文件? - How can I prevent my local files, which are deleted and ignored in remote repo, being deleted when pull from git? 如何将代码从eGit的主服务器中提取到Eclipse IDE中的本地分支? - How to pull code from the master in eGit to my local branch in eclipse IDE? 如何将本地 master 拉入本地分支 - How to pull local master into local branch git-从本地分支如何从master下拉提交 - git - from a local branch how to pull down commits from master 删除了本地主分支 - Deleted local master branch 如何将更新从Bitbucket上的远程(裸)主存储库提取到本地裸主存储库? - How to pull updates from a remote (bare) master repo at Bitbucket to a local bare master repo? 在Git中将本地仓库从主仓库切换到分支机构 - Switch local repo from master to branch in Git 有人能告诉我如何让我的本地仓库上的主分支反映远程仓库上的主分支吗? - Can someone tell me how I can get the master branch on my local repo to reflect the master branch on the remote repo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM