Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of remote origin/HEAD pointing to origin/master?

Tags:

git

Recently I've changed my origin remotes on two different replicated servers.

Now I have this situation one on server everything is ok:

$git branch -a
 * master
 remotes/origin/master

On the other server I have this

$git branch -a
 * master
 remotes/origin/HEAD -> origin/master
 remotes/origin/master

Nothing serious since everything should work but, for cleaning sake, I'd like to have the identical situation.

So I tried:

git branch -d -r origin/HEAD

Answer is:

Deleted remote branch origin/HEAD (was 542d392).

But then I have :

$git branch -a
 * master
 remotes/origin/HEAD -> origin/master

I also tried to prune :

$git pull -p  origin master

But still the same... no chance yet to have it clean like the other srvr.

Any hint?

Many thanks

EDIT

Answering comment "what happened after git update-ref -d refs/remotes/origin/HEAD"

    koala@server:~/www$ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    koala@server:~/www$ git update-ref -d refs/remotes/origin/HEAD
    koala@server:~/www$ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
    koala@server:~/www$ git branch -r
      origin/HEAD -> origin/master
like image 514
koalaok Avatar asked Aug 29 '16 11:08

koalaok


People also ask

How do I get rid of origin master remote?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

What does remotes origin head -> Origin Master mean?

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.


Video Answer


1 Answers

The -> in the git branch output indicates that this is a symbolic reference: that is, the reference itself points not to a commit, but rather to another reference. (That other reference can also be symbolic, but at least ideally, following all these names eventually leads to a regular reference—a non-symbolic branch name—which points to the final commit.)

The problem here is that git branch does not know how to delete a symbolic reference. When you ask it to delete the remote-tracking branch origin/HEAD, it follows the symbolic reference, discovering that it's an alternate name for origin/master, and deletes origin/master instead.

The git remote command does, in later versions of Git at least, know how to remove this:

git remote set-head <name> --delete

which in this case would translate to git remote set-head origin -d (shortening --delete; see the documentation).

If your Git is not new enough to support this, you can use the "plumbing" command git symbolic-ref, which easily deletes symbolic references, except that you must spell them out in full:

git symbolic-ref -d refs/remotes/origin/HEAD

If your Git version is old enough to lack the -d flag here, you will have to remove the symbolic reference manually, by editing .git/packed-refs if needed (it may not be needed and if your Git is really old it may never be created) and removing the file .git/refs/remotes/origin/HEAD (which is either a plain-text file containing ref: and the name of the other branch, or is a symbolic link if your Git is really old).

The name may come back anyway on git fetch (I had this happen to me in some Git 1.6.* or 1.7.* versions, if I remember the version numbers correctly, after I deleted the ref manually). Different versions of Git exhibit different behaviors here.

like image 121
torek Avatar answered Sep 29 '22 17:09

torek