Git 切换分支报错 error: pathspec ‘XXX‘ did not match any file(s) known to git 报错解决方法

前言

最近协助隔壁组解决一些问题审计代码,因我没有提交代码,切换他们新分支时候出现错误。

问题

本地切换分支

git checkout xxx

报错

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

在这里插入图片描述

解决

1. 查看本地的所有的分支

查看本地的所有的分支中是否有同事新创建的分支

git branch -a

2. 获取所有分支

如果没看到,那么执行以下操作,这步是获取所有分支

git fetch

在这里插入图片描述

3. 执行完会看到提示

remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
Unpacking objects: 100% (4/4), 1.06 KiB | 90.00 KiB/s, done.
From codeup.aliyun.com:5eeb0689892c58bb7c394ab5/pxb/pxb-fronted
 * [new branch]      XXX -> origin/XXX

在这里插入图片描述

4. 切换到远程同事分支

git checkout origin/XXX

提示

Note: switching to 'origin/XXX'.

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 switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at dc877cd XXX

5. 新建并切换到同事的分支

现在可以看到自己的分支是一串数字字母,这时新建并切换到同事的分支

git checkout -b XXX

6. 跟远程的同事分支进行关联

git branch -u origin/XXX XXX

7. 时我们执行git pull即可

git pull

在这里插入图片描述

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值