Home > database >  Should git repo have three refs
Should git repo have three refs

Time:07-28

I recently detached the HEAD from my git repo and was able to remove it by just force pushing my code to main however now I'm seeing in git reflog that my most recent commit has multiple refs when I would think it should just be HEAD

git reflog output

6a5c0e3 (HEAD -> main, origin/main, origin/HEAD) HEAD@{0}: commit: Remove git test comment.
37c6a90 HEAD@{1}: checkout: moving from main to main
37c6a90 HEAD@{2}: checkout: moving from main to main
37c6a90 HEAD@{3}: commit: Make calculation use Sheet builder
86bc423 HEAD@{4}: commit: Testing git integrity
1cdb617 HEAD@{5}: commit: Fix sheet buttons for CalculationBuilder
a2d3086 HEAD@{6}: checkout: moving from main to a2d30861060c439995f7daa906064340d01e2424[![enter image description here][1]][1]

enter image description here

I would think that Refs should just be main or origin/main right?

CodePudding user response:

I think possibly you have misunderstood some terminology.

  • HEAD is just where git records which commit you currently have checked out. Your working copy will always have HEAD pointing at some particular commit (except for in a completely new repo with no commits in it yet).
  • main is the name of a branch. A branch in git is just a pointer to a single commit; the history of the branch is calculated by following the "parent" pointers backwards through each commit.
  • origin/main is your local cache of where some other copy's branch called "main" points; often, that's the same commit, because the other copy is a central server you've kept your code in sync with.
  • origin/HEAD is the "current commit" of the other copy; for a central server, that generally tracks the "default branch" of the repository.

So, if what you currently have checked out is the branch called "main", which is the same as the remote branch called "main", and that's the default branch on the remote server, all four refs will point to the same commit. That's perfectly normal.

When you get a "detached HEAD", it just means you've checked out something other than a branch - a tag, or a particular commit by its hash. In that case, and only that case, the current commit would be pointed to by HEAD but not by any named branch.

  • Related