Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No remotes/origin/HEAD with gitlab

Tags:

git

gitlab

I'm pretty new to git, but I've been playing around with it on a remote server I set up and I'm pretty sure that I understand the basics.

I just set up gitlab and pushed some of my code to a new project on it. What I did was:

  1. Get all my code in a directory
  2. git init
  3. git add .
  4. git commit -m "Initial commit"
  5. git push origin master

Where origin was set up with:

git remote add origin [email protected]:myproject.git

Now when I do git branch -a I see:

* master
  remotes/origin/master

Whereas when I was playing around before, I always saw:

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

I understand that the head is a pointer the currently checked out branch, so shouldn't it exist on the origin? Why wasn't it created?

like image 313
Cameron Ball Avatar asked Nov 28 '12 07:11

Cameron Ball


People also ask

What is git remotes origin head?

What is Origin (or Remote Head) in Git? The word origin is an alias that Git created to replace the remote URL of a remote repository. It represents the default branch on a remote and is a local ref representing a local copy of the HEAD in the remote repository.

Is git head local or remote?

Git makes note of this current branch in a file located inside the Git repository, in . git/HEAD . (This is an internal file, so it should not be manually manipulated!) In this example case, a local branch named "master" is the current HEAD.

What does remotes origin head -> Origin Master mean?

It references the default branch that will be checked out when you are cloning the remote repo.

How do I point my head to the origin master?

checkout the target commit (you're already stepping there, but just in case) move master pointer to that commit (no problem, since it is a forward move) checkout master branch in order to be stepping onto it (for future commits) push (no conflicts, no problems, just forward then OK)


1 Answers

Don't worry much about this remote HEAD. This line is simply artifact of the way original clone works, and represents state of remote's HEAD.

It can be considered as a default branch that is preferred by server (even on remote bare repository) - it will be checked out by your client git clone by default if -b branch option was not used.

Your local file .git/refs/remotes/origin/HEAD probably contains string ref: refs/remotes/origin/master now. You can remove it if you want (not that I recommend doing it, mind you), and git branch -a will not show it anymore.

Except for this usage of remote HEAD as default branch for first clone, for you state of remote HEAD never matters. You should only worry about state of real remote branches, not remote HEAD as it only makes sense for remote state as its default selected branch. And if remote is bare repository, it does not make much sense even on remote.

And the reason why you did not see remote HEAD when you did git remote add ..., git fetch, git pull is because in that case git did not have to make a decision on which default remote branch to pickup by default.

like image 117
mvp Avatar answered Oct 04 '22 20:10

mvp