Home > database >  Difference between Git local and remote HEAD
Difference between Git local and remote HEAD

Time:12-28

I have been reading and practicing with git. I have a question about the pointer HEAD. I understand that it is a special pointer that points to the current branch, but if I do git branch --all, all I see is this:

* Test_Branch_1
  main
  remotes/origin/HEAD -> origin/main
  remotes/origin/Test_Branch_1
  remotes/origin/main

This makes sense. I can see my remote main branch and HEAD pointing at it. But I also see a * next to Test_Branch_1 which seems to indicate that HEAD is also pointed at Test_Branch_1? If I look at my last commit on Test_Branch_1 by doing git log -1 I see something like:

commit checksum (HEAD -> Test_Branch_1)
Merge: ...
Author: ...
Date: ...

Again, HEAD appears to be pointing at Test_Branch_1. It would appear there is a local and remote version of HEAD? The local one keeps track of which branch I am on locally? In this case the local version of Test_Branch_1? And the remote version of HEAD never changes in practice (i.e., always points at main)?

Is that correct or am I misinterpreting this?

CodePudding user response:

Your interpretation is correct.

remotes/origin/HEAD is a local alias for a remote branch.
It points to what you want to be the default branch for origin allowing you to use origin instead of (for ex.) origin/main wherever it makes sense.
You can set/delete it with git remote set-head origin main / git remote set-head -d origin
Again this has no effects on the remote repository and is not shared with your team mates.

As a side note, because you can have multiple origins, you can have multiple remotes/.../HEAD.

For more info take a look at the doc of git remote set-head

  •  Tags:  
  • git
  • Related