为什么我在 git repo 中有两个主要分支?

问题描述

有人能解释一下这里发生了什么吗?为什么有两个主要分支,一个名为“origin/main”,另一个名为“main”

制作别名图

DRB@SamiUllah MINGW64 /d/30days_python/myscrapping (main)
$ alias graph="git log --all --decorate --oneline --graph

图表显示我有两个分支。所以,我决定将主分支与 起源/主要

DRB@SamiUllah MINGW64 /d/30days_python/myscrapping (main)
$ graph
* 593f35d (HEAD -> main) Reorganized files of this repo
* 92fbed4 (origin/main) First commit from local repo
* eaf216d Initial commit

结帐时,它说:您处于“分离头”状态。

DRB@SamiUllah MINGW64 /d/30days_python/myscrapping (main)
$ git checkout origin/main
Note: switching to 'origin/main'.

You are in 'detached HEAD' state. You can look around,make experimental
changes and commit them,and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create,you may
do so (Now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is Now at 92fbed4 First commit from local repo

DRB@SamiUllah MINGW64 /d/30days_python/myscrapping ((92fbed4...))
$ git checkout main
PrevIoUs HEAD position was 92fbed4 First commit from local repo
Switched to branch 'main'

解决方法

origin 是远程存储库。

git remote -v 将列出所有远程存储库。

远程仓库有名字。通常为远程存储库选择“来源”。

您看到两个主要分支,因为 - 远程存储库和您的本地存储库具有相同的分支