如何在 Git 中切换分支?

问题描述 投票:0回答:2

我已执行以下行以切换到我的队友创建的新分支:

git checkout with-backend

我收到以下错误:

错误:路径规范“with-backend”与 git 已知的任何文件不匹配

我尝试执行这个命令:

git branch -a

我的队友创建的 with-backend 分支未列出。以下是列出的结果:

* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
git github github-actions github-for-windows
2个回答
3
投票

首先,切换分支是通过

git switch
(自 Git 2.23,2019 年第 3 季度开始)完成的,而不是
git checkout
(它试图同时管理文件和分支,使其变得令人困惑

其次,

git switch with-backend
将在
git fetch
之后起作用,因为如果它是“猜测”模式:

如果未找到

<branch>
,但在一个远程(称为
<remote>
)中确实存在一个具有匹配名称的跟踪分支,则视为相当于

$ git switch -c <branch> --track <remote>/<branch>

2
投票

在开始工作之前,请确保始终从存储库中提取最新更改

git 获取<-- fetches all the latest changes from remote repo

git拉<-- It is one step ahead of git fetch, it fetches remote changes and also merge local branch with remote branch

© www.soinside.com 2019 - 2024. All rights reserved.