git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: howto to run git without a master branch

From
Torsten Bögershausen <tboegi@web.de>
Date
Mar 9, 2014, 07:46 UTC
Message-ID
<531C1C69.6080809@web.de>
In-Reply-To
<531B8D91.6020800@ist.utl.pt>
On 2014-03-08 22.37, Carlos Pereira wrote:
Show 14 quoted lines
> Hi,
> git newbie here.
> 
> I would like to work with two main branches: master-g and master-x, instead of the usual master, and apparently git does not like this.
> 
> After creating a local repository with these two branches, and a server repository with git init --bare, and pushing the two branches:
> 
> git remote add origin foo@bar:~/path/test.git
> git push origin master-g
> git push origin master-x
> 
> everything seems fine, but cloning:
> git clone foo@bar:~/path/test.git
> terminates with a warning: remote HEAD refers to nonexistent ref, unable to checkout.

This is because Git is trying to be nice: When you clone, it tries to checkout a branch for you.

What happens when you only have 1 branch, lets say master-x? If I clone the bare repo here, with only 1 branch, this branch is automatically checked out (tested on 1.8.5.2)

What happens when you have 2 branches on the server? Git really can not make a decision which one is the right one to check out for you, so if you have 2 branched like "master" and "develop", it checks out the "master" branch for you.

But if you have "master-x" and "master-g" then Git has no clue, which one could be you favorite one (and neither have I)

What does "git branch" say?
(I think nothing)
What does "git branch -r" say?
(I think "origin/master-g" and "origin/master-x")
  
Show 12 quoted lines
> 
> On the original local repository, I have:
>>cat HEAD
> ref: refs/heads/master-x
> 
> But on the server repository or the clone repository, HEAD points to master branch, that does not exist:
>>cat HEAD
> ref: refs/heads/master
> 
> Replacing in the HEAD file, master by master-g (on the server before cloning, or on the clone after cloning) seems to solve the problem.
> 
> Shall I worry about this? does my fix (editing directly HEAD on the server) fixes really the problem? 
No
>what would be the correct procedure to avoid this?

(Don't worry if there is a warning, when Git tries to be nice) (Or feel free to send a patch to this list which improves the user experience)

> 
> Thank you!
> Carlos Pereira,
Previous: Carlos PereiraNext: Carlos Pereira
Message 2 of 7 in “howto to run git without a master branch”
  1. Carlos PereiraMar 8, 2014
  2. Torsten BögershausenMar 9, 2014
  3. Carlos PereiraMar 9, 2014
  4. KevinMar 9, 2014
  5. Ilya BobyrMar 9, 2014
  6. Carlos PereiraMar 9, 2014
  7. Andreas SchwabMar 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.