我可以在我的git项目上设法导航思考不同的分支机构
我正在开发我的第一个 GIT 存储库,它有几个分支。通过这节课,我们要在不同的分支之间进行切换。
目前,我已经在 Visual Code Studio 上克隆了存储库,它运行良好。项目在vscode上正常打开。
当我尝试切换分支时,它不起作用。 当我输入:gitbranch
时,它只显示:* main
。
不过,该项目应该有更多的分支! 这是 git 链接:https: //github.com/OpenClassrooms-Student-Center/debuggez-l-interface-de-votre-site/tree/main
I'm working on my first GIT repo, which has several branches. Through the lesson, we have to switch between different branches.
At the moment , I've been cloning on Visual Code Studio the repo, which is working fine. The project opens normally on vscode.
When I try to switch branches, it doesn't work.
When I type : git branch
it only shows me : * main
.
However, there should be more branches on the project!
Here is the git link : https://github.com/OpenClassrooms-Student-Center/debuggez-l-interface-de-votre-site/tree/main
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,
gitbranch
显示本地分支。当您获取存储库时,其分支以远程分支开始 - 它们仍然会被获取,但仅在
remotes/repo/branchname
下开始。当您创建跟踪远程分支的本地分支时,默认情况下会对 master -> 执行此操作。 remotes/origin/master (或者在您的情况下为
main ->remotes/origin/main
),那么您就有一个本地分支。您想查看所有分支:
gitbranch [--list] -a|--all
来查看所有内容。当您签出尚不存在但与远程分支名称匹配的本地分支时,它将被设置为正确跟踪远程,即使您在简单运行 gitbranch 时看不到它代码>.
但你没有尝试切换分支。您查看存在哪些分支(没有意识到它只显示本地分支),但从未实际运行 git checkout partie-1/chapitre-1/section-1 或其他内容。正确的?
即使在了解上述内容之前,您也应该对尝试这样做感到放松:如果出现问题,您随时可以再次删除分支,并且签出失败不会产生任何副作用。如果您拼错了分支名称,它不会破坏您的存储库或丢失您的工作。
您还应该养成检查在线文档的习惯。运行 git helpbranch 会显示所有这些选项。
输出示例:
PS。同一分支同时拥有本地和远程版本的原因是它们可能会有所不同:您需要能够在不更改本地副本的情况下获取远程版本,以便比较它们并决定要做什么来解决这个问题(通常是合并或变基)。
By default
git branch
shows local branches.When you fetch a repo, its branches start out as remote branches - they're still fetched, but start off only under
remotes/repo/branchname
.git branch [--list] -r|--remote
to see these.When you create a local branch that tracks a remote branch, as is done by default for
master -> remotes/origin/master
(or in your case formain -> remotes/origin/main
), then you have a local branch.git branch [--list]
to see these.You want to see all branches:
git branch [--list] -a|--all
to see everything.When you checkout a local branch that doesn't already exist, but matches the name of a remote branch, it will be set up to track the remote correctly even though you couldn't see it when simply running
git branch
.But you didn't try to switch branches. You looked to see what branches existed (without realizing it only showed the local ones) and never actually ran
git checkout partie-1/chapitre-1/section-1
or whatever. Right?You should feel relaxed about trying this even before you knew the above: you can always delete the branch again if something went wrong, and
checkout
failing has no side-effects whatsoever. If you mis-spell a branch name, it isn't going to ruin your repo or lose your work.You should also get in the habit of checking the online documentation. Running
git help branch
shows all these options.Sample output:
PS. The reason for having both local and remote versions of the same branch is that they can diverge: you need to be able to fetch the remote version without altering your local copy, in order to compare them and decide what to do about it (usually merging or rebasing).
如果您仅在本地克隆中看到
main
分支,则您可能想执行git提取
获取远程存储库中存在的所有其他分支。If you only see the
main
branch in your local clone your might want to do agit fetch
to get all the other branches that exist in the remote repository.