我无法在我的 GIT 项目中浏览不同的分支

I can't manage to navigate thought different branches on my GIT project

我正在处理我的第一个 GIT 存储库,它有几个分支。通过课程,我们要在不同的分支之间切换。

目前,我一直在 Visual Code Studio 上克隆 repo,它运行良好。该项目在 vscode.

正常打开

当我尝试切换分支时,它不起作用。 当我输入:git branch 它只显示我:* main.

但是,项目上应该有更多的分支! 这是 git link :https://github.com/OpenClassrooms-Student-Center/debuggez-l-interface-de-votre-site/tree/main

如果您在本地克隆中只看到 main 分支,您可能想要执行 git fetch 以获取远程存储库中存在的所有其他分支。

When I type : git branch it only shows me : * main

默认情况下 git branch 显示 local b运行ches.

当你获取一个 repo 时,它的 b运行ches 开始时是 remote b运行ches - 它们仍然被获取,但是开始了仅在 remotes/repo/branchname.

  • 运行git branch [--list] -r|--remote看这些

当您创建一个跟踪远程 b运行ch 的本地 b运行ch 时,默认情况下 master -> remotes/origin/master(或者您的 main -> remotes/origin/main), 那么你就有了一个本地 b运行ch.

  • 运行git branch [--list]看这些

你想看所有 b运行ches:

  • 运行git branch [--list] -a|--all什么都看

当您检出一个不存在但与远程 b运行ch 名称匹配的本地 b运行ch 时,它将被设置为正确跟踪远程甚至虽然你在 运行ning git branch.

时看不到它

When I try to switch branches, it doesn't work

但是你没有尝试切换b运行ches。您查看存在什么 b运行ches(没有意识到它只显示了本地的),但实际上从未 运行 git checkout partie-1/chapitre-1/section-1 或其他任何东西。对吗?

即使在您知道上述内容之前,您也应该对尝试感到放松:如果出现问题,您可以随时再次删除 b运行ch,并且 checkout 失败没有任何 side-effects。如果您 mis-spell 一个 b运行ch 名称,它不会破坏您的存储库或丢失您的工作。

您还应该养成查看在线文档的习惯。 运行ning git help branch 显示所有这些选项。


示例输出:

$ git branch
* main

$ git branch -r
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

PS。具有相同 b运行ch 的本地和远程版本的原因是它们可能会有所不同:您需要能够获取远程版本 而无需 更改您的本地副本,以便比较它们并决定如何处理(通常是合并或变基)。