Git无法切换远程分支error:pathspec'origin/XXXX'didnotmatchanyfile(s)knowntogit

首页 编程分享 LINUX丨SYSTEM 正文

Rotcod 转载 编程分享 2020-06-27 23:25:06

简介 文末直接查看解决方法 以下为问题处理过程,以切换到master分支为例 本地只有部分分支,当想切换到其它远程分支时报错: $ git checkout master error: path...


文末直接查看解决方法

以下为问题处理过程,以切换到master分支为例

本地只有部分分支,当想切换到其它远程分支时报错:

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

查看所有分支,发现没有想要切换的分支

$ git branch -a
* dev
  remotes/origin/dev

fetch所有分支

git fetch --all Idfetch所有分支

然后git branch -a发现还是没有想要切换的分支,尝试直接fetch指定分支

$ git fetch master
fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

提示分支不存在。查看仓库,发现分支并未移除,依然存在。

查看文件 项目路径/.git/config, 发现remote只添加了单一分支

[remote "origin"]
	url = http://XXXXXXXXXXX/XXXXXXXXXXX.git
	fetch = +refs/heads/dev:refs/remotes/origin/dev

修改为

[remote "origin"]
	url = http://XXXXXXXXXXX/XXXXXXXXXXX.git
	fetch = +refs/heads/*:refs/remotes/origin/*

再次fetch分支,成功解决问题

$ git fetch --all
Fetching origin
From http://XXXXXXXXXXX/XXXXXXXXXXX
 * [new branch]      master     -> origin/master
 
$ git branch -a
* dev
  remotes/origin/dev
  remotes/origin/master
  
$ git checkout master
Switched to a new branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.

转载链接:https://my.oschina.net/vxb/blog/4259690


Tags:


本篇评论 —— 揽流光,涤眉霜,清露烈酒一口话苍茫。


    声明:参照站内规则,不文明言论将会删除,谢谢合作。


      最新评论




ABOUT ME

Blogger:袅袅牧童 | Arkin

Ido:PHP攻城狮

WeChat:nnmutong

Email:nnmutong@icloud.com

标签云