> 文章列表 > git fatal: ‘xxx‘ is not a commit and a branch ‘xxx‘ ‘ cannot be created from it

git fatal: ‘xxx‘ is not a commit and a branch ‘xxx‘ ‘ cannot be created from it

git fatal: ‘xxx‘ is not a commit and a branch ‘xxx‘ ‘ cannot be created from it

错误背景

当拉取一个git远程仓库分支时报错:

命令:git checkout -b 本地分支名 远程分支名

报错:fatal: 'origin/dev_v2.8.4_v10.74.1' is not a commit and a branch 'dev_v2.8.4_v10.74.1' cannot be created from it

主要原因

远程新建的分支没有更新到本地。实际上,git仓库分为本地仓库和远程仓库,我们用checkout命令是从本地仓库中找要检出的分支的。本地仓库只有在进行网络请求时才会跟远程仓库交互,比如fetch命令。

处理方式

将远程仓库数据到本地,使用两个命令:

1:git fetch origin

2:git remote update origin --prune

执行完这两步后在重新拉下分支就ok啦。

小提示:

git remote update 用于更新远程仓库的信息。(它会下载最新的版本库数据,并更新本地仓库的所有指针(例如远程分支和远程标签)。这样,你就可以在本地仓库中看到最新的远程分支和标签了)

git fetch 命令与一个远程程序的仓库交互,并且将远程程序库中有但在当前仓库中没有的所有信息拉下来后仍然存储在你本地数据库中。