如何在 git 中切换分支?
How do i switch branch in git?
我已经执行了下面这行来切换到我队友创建的新分支:
git checkout with-backend
我收到以下错误:
错误:pathspec 'with-backend' 不匹配 git
已知的任何文件
我试过执行这个命令:
git branch -a
队友创建的with-backend分支没有列出来。以下是列出的结果:
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
确保在开始工作之前始终从存储库中提取最新更改
git fetch <-- 从远程仓库中获取所有最新更改
或
git pull <-- 它比 git fetch 领先一步,它获取远程更改并将本地分支与远程分支合并
首先,切换分支是用git switch
(since Git 2.23, Q3 2019), not git checkout
(which tries to manage both files and branches, making it confusing)
完成的
其次,git switch with-backend
将在 git fetch
之后工作,因为如果它的“猜测”模式:
If <branch>
is not found but there does exist a tracking branch in exactly one remote (call it <remote>
) with a matching name, treat as equivalent to
$ git switch -c <branch> --track <remote>/<branch>
我已经执行了下面这行来切换到我队友创建的新分支:
git checkout with-backend
我收到以下错误: 错误:pathspec 'with-backend' 不匹配 git
已知的任何文件我试过执行这个命令:
git branch -a
队友创建的with-backend分支没有列出来。以下是列出的结果:
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
确保在开始工作之前始终从存储库中提取最新更改
git fetch <-- 从远程仓库中获取所有最新更改
或
git pull <-- 它比 git fetch 领先一步,它获取远程更改并将本地分支与远程分支合并
首先,切换分支是用git switch
(since Git 2.23, Q3 2019), not git checkout
(which tries to manage both files and branches, making it confusing)
其次,git switch with-backend
将在 git fetch
之后工作,因为如果它的“猜测”模式:
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat as equivalent to$ git switch -c <branch> --track <remote>/<branch>