Skip to contentSkip to conversation

howto to run git without a master branch

DISCUSSION Carlos Pereira 5 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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:

Quoted 1 line

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:

Quoted 1 line

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,

#1 lore raw
Quoted 7 lines · Carlos Pereira

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:

Quoted 7 lines

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")

Quoted 5 lines

On the original local repository, I have:

Quoted 1 line

cat HEAD

ref: refs/heads/master-x

Quoted 7 lines

But on the server repository or the clone repository, HEAD points to master branch, that does not exist:

Quoted 1 line

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

Quoted 1 line

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)

Quoted 3 lines

Thank you!
Carlos Pereira,

#2 lore raw
Quoted 17 lines · Torsten Bögershausen
Quoted 10 lines

After creating a local repository with these two branches, and a server repository with git init --bare, and pushing the two branches:

Quoted 8 lines

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)

Quoted 8 lines

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

Quoted 6 lines

What does "git branch" say?
(I think nothing)
What does "git branch -r" say?
(I think "origin/master-g" and "origin/master-x")

#3 lore raw
Quoted 21 lines · Carlos Pereira
Quoted 20 lines · Torsten Bögershausen
Quoted 8 lines

After creating a local repository with these two branches, and a server repository with git init --bare, and pushing the two branches:

Quoted 6 lines
Quoted 1 line

git remote add originfoo@bar:~/path/test.git

git push origin master-g
git push origin master-x

Quoted 1 line

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.

Quoted 5 lines
Quoted 2 lines

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?

Quoted 3 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.

#4 lore raw
Quoted 2 lines

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)

Quoted 2 lines

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.

Quoted 1 line

I do not think there should be any issues.

Thank you very much for your answers,

Carlos

#5 lore raw
In reply to Ilya Bobyr
Quoted 1 line · Ilya Bobyr

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.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#6 lore raw
In reply to Carlos Pereira

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.

Quoted 67 lines · Carlos Pereira
Quoted 28 lines · Torsten Bögershausen
Quoted 13 lines

After creating a local repository with these two branches, and a server repository with git init --bare, and pushing the two branches:

Quoted 9 lines
Quoted 1 line

git remote add originfoo@bar:~/path/test.git

git push origin master-g
git push origin master-x

Quoted 1 line

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.

Quoted 4 lines

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

Quoted 6 lines

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html