threads / discuss / 36101

howto to run git without a master branch

Subject: howto to run git without a master branch

## tl;dr

7 messages between Mar 8, 2014 and Mar 10, 2014.

replies: 6people: 5as markdown or json

Carlos Pereira· Mar 8, 2014, 21:37 UTC · lore

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.

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? what would be the correct procedure to avoid this?

Thank you! Carlos Pereira,

Torsten Bögershausen· Mar 9, 2014, 07:46 UTC · re: Carlos Pereira · lore

Re: howto to run git without a master branch

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,
Carlos Pereira· Mar 9, 2014, 19:54 UTC · re: Torsten Bögershausen · lore

Re: howto to run git without a master branch

On 03/09/2014 07:46 AM, Torsten Bögershausen wrote:
Show 25 quoted lines
>> 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 originfoo@bar:~/path/test.git
>> >  git push origin master-g
>> >  git push origin master-x
>> >  
>> >  everything seems fine, but cloning:
>> >  git clonefoo@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)
>    

The problem is on the server repo, the cloned repo is just a consequence. After initializing the server repo and pushing two branches master-g and master-x there is no master branch. Therefore the HEAD file should not point to a master branch that does not exist: ref: refs/heads/master

It could point to master-g (the first branch to be pushed) or master-x (the last branch to be pushed), depending of the criterion used by git, but pointing to something that does not exist seems weird and is the cause of the further complaints when the whole repository is cloned...

I forgot to say that the git version is 1.7.2.5 in both the initial repo and the server repo (probably this issue was fixed in newer versions?)

As I said, editing directly the HEAD text file on the server, and replacing master by master-g (or master-x) seems to solve the problem. My question is: is that enough? or shall I expect further issues down the road?

Thank you very much,
Carlos
Show 6 quoted lines
> What does "git branch" say?
> (I think nothing)
> What does "git branch -r" say?
> (I think "origin/master-g" and "origin/master-x")
>
>    
Kevin· Mar 9, 2014, 20:00 UTC · re: Carlos Pereira · lore

Re: howto to run git without a master branch

HEAD on the remote repo is indeed used to determine what to check out when cloning. It's quite normal to change it to anything you like. To change it, you usually use git symbolic-ref HEAD master-x instead of directly editing that file.

On Sun, Mar 9, 2014 at 8:54 PM, Carlos Pereira <jose.carlos.pereira@ist.utl.pt> wrote:

Show 67 quoted lines
> On 03/09/2014 07:46 AM, Torsten Bögershausen wrote:
>>>
>>> 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 originfoo@bar:~/path/test.git
>>>
>>> >  git push origin master-g
>>> >  git push origin master-x
>>> >  >  everything seems fine, but cloning:
>>> >  git clonefoo@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)
>>
>
> The problem is on the server repo, the cloned repo is just a consequence.
> After initializing the server repo and pushing two branches master-g and
> master-x there is no master branch. Therefore the HEAD file should not point
> to a master branch that does not exist: ref: refs/heads/master
>
> It could point to master-g (the first branch to be pushed) or master-x (the
> last branch to be pushed), depending of the criterion used by git, but
> pointing to something that does not exist seems weird and is the cause of
> the further complaints when the whole repository is cloned...
>
> I forgot to say that the git version is 1.7.2.5 in both the initial repo and
> the server repo (probably this issue was fixed in newer versions?)
>
> As I said, editing directly the HEAD text file on the server, and replacing
> master by master-g (or master-x) seems to solve the problem. My question is:
> is that enough? or shall I expect further issues down the road?
>
> Thank you very much,
>
> Carlos
>
>> What does "git branch" say?
>> (I think nothing)
>> What does "git branch -r" say?
>> (I think "origin/master-g" and "origin/master-x")
>>
>>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ilya Bobyr· Mar 9, 2014, 22:16 UTC · re: Carlos Pereira · lore

Re: howto to run git without a master branch

On 3/9/2014 12:54 PM, Carlos Pereira wrote:
Show 38 quoted lines
> On 03/09/2014 07:46 AM, Torsten Bögershausen wrote:
>>> 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 originfoo@bar:~/path/test.git
>>> >  git push origin master-g
>>> >  git push origin master-x
>>> >  >  everything seems fine, but cloning:
>>> >  git clonefoo@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)
> The problem is on the server repo, the cloned repo is just a 
> consequence. After initializing the server repo and pushing two 
> branches master-g and master-x there is no master branch. Therefore 
> the HEAD file should not point to a master branch that does not exist: 
> ref: refs/heads/master
>
> It could point to master-g (the first branch to be pushed) or master-x 
> (the last branch to be pushed), depending of the criterion used by 
> git, but pointing to something that does not exist seems weird and is 
> the cause of the further complaints when the whole repository is 
> cloned...
There is a "git remote set-head" to manipulate HEAD in a remote repository.

The fact that it is not set when you push master-x and master-y could be justified to some extent. I think that this only applies to a case when you are pushing into a repository that have no branches. Consider that you do not have to push only one branch, you may push any set of branches you want. And I do not think that branches in the set have any meaningful order. Also, your local HEAD does not necessary point to the "most reasonable branch to checkout when you clone". It is just your current branch. Now the questions is, how should the remote repository determine what to change HEAD to?

I agree that this might be viewed as a user experience issue. But I can not come up with a possible solution. Can you?

Show 8 quoted lines
> I forgot to say that the git version is 1.7.2.5 in both the initial 
> repo and the server repo (probably this issue was fixed in newer 
> versions?)
>
> As I said, editing directly the HEAD text file on the server, and 
> replacing master by master-g (or master-x) seems to solve the problem. 
> My question is: is that enough? or shall I expect further issues down 
> the road?

I do not think there should be any issues. Basically if your repository is not using master as the "most reasonable branch to checkout when you clone" you need to do "git remote set-head" when you are preparing the shared repository. I guess that in most setups there will be just one shared repository.

Carlos Pereira· Mar 9, 2014, 23:58 UTC · re: Ilya Bobyr · lore

Re: howto to run git without a master branch

> There is a "git remote set-head" to manipulate HEAD in a remote 
> repository.

Thanks, that is useful (like git symbolic-ref HEAD master-x suggested by Kevin, much better than editing the text file)

> I agree that this might be viewed as a user experience issue.
> But I can not come up with a possible solution.  Can you?

The branch where the user was when he/she pushed the repo to the server? it would be his/her responsibility to checkout the proper branch before pushing... if that was not good enough than he/she could always use git remote set-head... my point is: pointing to a bad branch that exists seems better than pointing to a branch that does not exist...

Anyway I agree this is not important, as we can easily change HEAD.
> I do not think there should be any issues.
Thank you very much for your answers,
Carlos
Andreas Schwab· Mar 10, 2014, 09:30 UTC · re: Ilya Bobyr · lore

Re: howto to run git without a master branch

Ilya Bobyr <ilya.bobyr@gmail.com> writes:
> There is a "git remote set-head" to manipulate HEAD in a remote repository.

This is misleading. The command does nothing on the remote side, it only changes the refs/remote namespace in your repository. The purpose is to change what branch the ref remote/<name> resolves to, ie. without explicit branch name.

(The only command that manipulates the remote repository is git push, and the plumbing beneath that. To change HEAD in a remote repository you need filesystem access to it.)

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads