0

There are LOTs of answers pertaining to this on SO but none of them seem to work for me.

I'm using git ver. 2.25.1.

git remote show origin

shows:

 remote origin   Fetch URL: /opt/ideatree   Push  URL: /opt/ideatree  
 HEAD branch: dotImport   
 Remote branches:
     dotImport      tracked
     getProdWorking tracked
     master         tracked   Local branch configured for 'git pull':
     master merges with remote master   Local ref configured for 'git push':
     master pushes to master (up to date)

Local is fine. It's the "HEAD branch: dotImport" that I'm trying to alter, to "HEAD branch: master".

Since 'dotImport' is not the main branch eventually I will want to delete it on remote, but that can't happen as long as HEAD is set to dotImport:

git push origin --delete dotImport
remote: error: By default, deleting the current branch is denied, because the next
remote: 'git clone' won't result in any file checked out, causing confusion.

Attempting to re-assign HEAD:

git symbolic-ref HEAD refs/heads/master

has no effect.

git remote set-head origin --auto

yields:

origin/HEAD set to dotImport

It just won't budge.

Here's another view of what it looks like on the remote, which disagrees with what 'git remote show origin' says:

 git branch -r
  origin/HEAD -> origin/master
  origin/dotImport
  origin/master

Maybe I'm missing a step which updates the remote with HEAD changes made locally?

Ron
  • 357
  • 1
  • 6
  • 18

2 Answers2

1

The answers I'm reading on SO (answers to that question or that question for example) seem to indicate it can't be done -- not through git alone from a clone of the remote.

You should see if you can access the central repo (if you have a self hosted gitlab server for instance) and change HEAD from the central repo itself, or go through the web GUI (for github.com for instance) to set the "default branch" for your project.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

The URL for origin is /opt/ideatree. This has no "scheme" part (no https:// or git:// or ssh:// in front), so it's just a local file: your Git software, on your machine, will call up Git software on ... your own machine. It will call itself! It will ask itself—another instance of itself—to cd /opt/ideatree, where it should find another Git repository.

It is this other Git repository, over in /opt/ideatree, that has branch dotImport checked out. That produces these error messages (from the "other" Git—the second Git instance, running in /opt/ideatree):

error: By default, deleting the current branch is denied, because the next
'git clone' won't result in any file checked out, causing confusion.

These error messages get relayed to your own Git, which sticks the word remote: in front of each line, resulting in the two lines you see.

Here's another view of what it looks like on the remote, which disagrees with what 'git remote show origin' says:

 git branch -r
  origin/HEAD -> origin/master
  origin/dotImport
  origin/master

How did you obtain this view? (If you got it by running git branch -r locally, in your own clone, be aware that -r shows what your clone has at the moment, not what the remote has at the moment. Running git fetch updates what your clone has, except that it doesn't update origin/HEAD; to make that happen you must run git remote origin set-head --auto.) It does indeed disagree with what your git remote show origin said, and also with the error message you got.

You should, given appropriate permissions at least, be able to:

cd /opt/ideatree
git checkout master

to switch /opt/ideatree to branch master. But if /opt/ideatree is itself meant to be the target of git push operations, it's usually wisest to set it up as a bare repository: one with no working tree at all. In this case, nothing is checked out, which means no branch can be worked-on, which means any branch name can be pushed-to (though the HEAD branch cannot be deleted, which means you want to use the git symbolic-ref command to adjust it if you ever decide to use main instead of master for instance). All of this just happens over in /opt/ideatree though; once you're done there, you cd back to the place where you do your work.

(If you want to be able to do a push-to-deploy, you'll need some additional glue code. Git makes a poor deployment system, but I don't have any other system to recommend.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • Basically this restates the problem then gives the solution that @leGEC gave, but thanks. – Ron Sep 11 '21 at 01:37
  • Um, no: I point out that the "remote" is mounted locally, so you can do what you need to *locally*, and also point out that you're setting yourself up for future unhappiness. Whether these extra details are *useful* is up to you. – torek Sep 11 '21 at 03:35
  • Having remote on the same machine is intentional. And it was set up as a bare repository. – Ron Sep 11 '21 at 03:41
  • 1
    You did not mention either of these in your question. If you had, my answer would have been: *Just `cd /opt/ideatree` before running `git symbolic-ref`.* – torek Sep 11 '21 at 03:44