gitgit-detached-head

Why do I have two main branches in git repo?


Can some explain what is happing here? Why is there two main branches one named "origin/main" and other one is "main"

Made an alias graph

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

Graph shows I have two branches. So, I decided to merge main branch with origin/main

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

On checkingout, it says: You are in 'detached HEAD' state.

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'

Solution

  • origin is a remote repository.

    git remote -v will list all remote repositories.

    Remote repository have names. Quite often "origin" is choosen for a remote repository.

    You see two main branches because - the remote repository and your local repository have the same branch