Use main as default branch name
Quoted 16 lines · Jonathan Nieder
Quoted 15 lines · Jeff King
Quoted 13 lines · Felipe Contreras
Quoted 5 lines · Jeff King
Yes, I have run into that, and it's definitely annoying. The refs/remotes/<remote>/HEAD symref is created by clone, but is not updated by "fetch". That's intentional, because it's supposed to represent a local choice (that is merely seeded by the remote side). But it seems like adding it if it's missing might be reasonable.
The equivalent of this choice is in "git remote add -m":
With
-m <master>option, a symbolic-refrefs/remotes/<name>/HEADis set up to point at remote's<master>branch. See also the set-head command.
Quoted 6 lines
Quoted 4 lines
Wow, I'm not sure how that option escaped my notice for all these years. Of course it would be much more useful if it pulled the value from the remote HEAD (but again, unless we use "-f" we are not contacting the remote at all).
When would I want this implicit "set-head -a" and *not* want "-f"?
This is what I often do:
git remote add origin $url
git fetch origin
That should work (update origin/HEAD), and it currently doesn't.
Quoted 27 lines
Quoted 4 lines
E.g., remote.origin.updateHEAD that can be set to one of:
- never; do not touch it
Quoted 8 lines
- create-if-missing; as discussed here
- always; update it on every fetch
And then it is just a question of what the default is. Currently it is "never". I suspect most people would be happy with "always", but it does break some existing flows. But perhaps "create-if-missing" is a good medium.
Thanks for bringing this up --- this is something I had been interested in as well but hadn't gotten around to contacting the list about it.
The default value for a config setting like this has two purposes:
- it makes the config setting for affected people who have not discovered it
- it provides a sensible, predictable standard behavior
Those two goals are often in tension, as they were for example when setting the default for push.default.
Quoted 6 lines
If I consider them separately:
- to make as smooth a transition as possible for people who were relying on "git remote set-head", a good behavior would be to *fail the fetch* when the remote HEAD changes. That would force the user to make a choice between "never" and "always".
We don't need to fail the fetch, we can print a warning so the user can decide what to do next, including ignoring the warning.
Moreover, since projects rarely change the HEAD, we might want to print the warning always, until the user sets the configuration.
Quoted 6 lines
- one way to relax that without hurting that goal too much would be to fail the fetch when the remote HEAD changes from something other than "master" or "main". That way, the common case (moving from a default to a project-appropriate setting) would work without friction, and in other cases the user could make a choice between "never" and "always".
This thread started in an attempt to move away from hard-coded values. This doesn't help in my opinion.
Quoted 6 lines
- all that said, the default that I prefer is simply "always". Like Felipe hinted, this is a simple, intuitive behavior that most people would expect.
As a transition plan, I can imagine going from one of those first two to the third after some appropriate period of time has passed.
I think the default should be "missing", after a warning period. And perhaps change it to "always" in the next major version, but that basically gets rid of the manual "origin/HEAD" that seems to have been there since forever (at least 2007).
I personally don't see any point in manually setting the HEAD (I have never done so), but that's just me, others might.
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 4 lines · Jeff King
Quoted 2 lines · Felipe Contreras
The equivalent of this choice is in "git remote add -m":
Quoted 8 lines
Quoted 3 lines
With
-m <master>option, a symbolic-refrefs/remotes/<name>/HEADis set up to point at remote's<master>branch. See also the set-head command.Wow, I'm not sure how that option escaped my notice for all these years. Of course it would be much more useful if it pulled the value from the remote HEAD (but again, unless we use "-f" we are not contacting the remote at all).
Seems to come basically untouched since 2007:
b6f5da1e0f (Teach git-remote add to fetch and track)
Quoted 4 lines
And then it is just a question of what the default is. Currently it is "never". I suspect most people would be happy with "always", but it does break some existing flows. But perhaps "create-if-missing" is a good medium.
Agreed. Personally I don't see any problem with "create-if-missing", but creating a configuration and defaulting to "never" should be a good first step.
I'm sending an RFC patch to that effect.
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 6 lines · [email protected] (Eric W. Biederman) writes:
Quoted 3 lines · Johannes Schindelin via GitGitGadget
This is the big one. This changes the default of init.defaultBranch to main, reflecting what many open source projects already did (which was followed by GitHub, Azure Repos and others).
Quoted 7 lines
Can we please not simply replace one hard coded branch name with another?
Having a blessed name for the initially created branch continues to imply the branch has special significance. As the initially created branch does not have special significance can we please do something that does not imply that?
I personally am fond of this line of "let's not treat one single thing any special among others" approach, but I think the way people use the initially created branch tends to make it special at the end of the day.
While the project is still in its infancy, you may use that as the only branch until the tree of the project starts to take its shape, perhaps with subdirectories dedicated to sources, documentation, and overall build procedure, etc. Then you may start to fork different branches to work on topics that last more than one commit's worth of time and then it is likely you'd use the initially created branch as the integration branch, until you start to need the second and third integration branches. Like it or not, the primary integration branch would inevitably end up being something more special than others, and it is likely that using the initially created branch for that purpose would be the most convenient. There however may exist two or more equally significant branches, not just one special one, though, but it is reasonable to have at least one special one.
I think using some word that is derived from $(basename $(pwd)) as the name of the initial branch may be a more reasonable choice than using any single word that tries to fit everybody (which will *not* exist). When a user says "git init tinyshell" to start a project to create a tiny shell, "tinyshell" may be one reasonable choice to refer to its primary integration branch. Everything that goes into it will become part of the tinyshell project.
But if there is a woke-safe word that can refer to "the primary integration branch", calling the initially created branch with that word by default is also equally a reasonable approach. I personally do not like the word 'main' used as such, but the rest of the world seems to be moving in that direction, so being consistent with them would help users who want to do
mkdir project && cd project
git init
... some workflow specific 'git config' here ... git remote add $URL origin
git pull origin
and have it be an enhanced equivalent to
git clone $URL project
The latter will try to find the name used for the primary branch on the other side and use the same name; the former would not work that way, but if "git init" uses a fallback default that is most common, it would hurt less.
In any case, the updated version of these 28 patches no longer has the final "switch the fallback default to 'main'" step, and the good thing is that the other 27 patches will help us moving in any direction. If we choose to dynamically derive the initial branch name, these steps make sure that such a change won't break our testsuite.
Quoted 11 lines
Instead of having a fixed name across all repos for the initially created branch can we instead use the directory name of the repo for the branch name?
Advantages:
- The branch name that is somewhat meaningful to the creator of the git repo.
I have at least two repos where I wound up doing this by hand. So at least for me it is something I am doing anyway.
Direct "other side" of the coin is that the name meaningful to the creator may be different from project to project, so those who want to try peeking projects that are so far unknown to them will have to guess what that meaningful thing is. When visiting a random github repository and presented by 47 different branches, it would be more helpful for such a visitor to have a reliable "this is likely to be the primary integration branch" cue. Not having a convention is worse than having a convention some folks may find suboptimal from usability's point of view.
Quoted 2 lines
- Tools can not hard code the name of an initially created branch and expect it to work.
Cannot? Is this a dogmatic declaration?
If tools that are meant to work with variety of projects with a single "special" branch and do things relative to that special branch (e.g. perhaps the special branch is the primary integration branch, and the tool may list commits that are not yet in that branch), a toolsmith has multiple choices. The tool can take the name of the "special" branch from the end-user to be most flexible, of the tool can hardcode the most commonly used name for the "special" branch to be out-of-the-box useful for majority of projects. Most sensible folks may do the former, but I do not think the latter is a bad choice. And even those who do the former has to fall back to some hardcoded value when the user didn't give the name of the "special" branch, because end-users are greedy and will demand such a "convenience" feature, saying "in most repositories, this name is commonly used for the 'special' branch---why force us to type the same thing?"
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · [email protected] (Eric W. Biederman) writes:
- The branch name that is somewhat meaningful to the creator of the git repo.
I have at least two repos where I wound up doing this by hand. So at least for me it is something I am doing anyway.
Quoted 9 lines
Direct "other side" of the coin is that the name meaningful to the creator may be different from project to project, so those who want to try peeking projects that are so far unknown to them will have to guess what that meaningful thing is. When visiting a random github repository and presented by 47 different branches, it would be more helpful for such a visitor to have a reliable "this is likely to be the primary integration branch" cue. Not having a convention is worse than having a convention some folks may find suboptimal from usability's point of view.
But a convention is just that: a convention.
If we already know "origin/HEAD" is very likely pointing to the integration branch, then why do we need to know what that branch is called in that particular project?
Just refer to that branch as "origin/@", or just "origin".
That would work for projects that follow the convention, and those who don't. Why does the tool need to care?
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 5 lines · Felipe Contreras
If we already know "origin/HEAD" is very likely pointing to the integration branch, then why do we need to know what that branch is called in that particular project?
Just refer to that branch as "origin/@", or just "origin".
"git merge origin" turns into "git merge origin/HEAD", I think, and we had it for quite some time.
But repositories may not even have any origin to begin with. The one I am typing this message in certainly does not. And we need some fallback default when origin/HEAD cannot be used anyway, and that is where the convention comes in again. You cannot escape from it, and ...
Quoted 2 lines
That would work for projects that follow the convention, and those who don't. Why does the tool need to care?
... certainly it would not work for me.
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Felipe Contreras
If we already know "origin/HEAD" is very likely pointing to the integration branch, then why do we need to know what that branch is called in that particular project?
Just refer to that branch as "origin/@", or just "origin".
Quoted 8 lines
"git merge origin" turns into "git merge origin/HEAD", I think, and we had it for quite some time.
But repositories may not even have any origin to begin with. The one I am typing this message in certainly does not. And we need some fallback default when origin/HEAD cannot be used anyway, and that is where the convention comes in again. You cannot escape from it, and ...
I did not say the convention can be escaped, I said the convention can be minimized.
Since apparently there's already support for "origin/HEAD", a lot of documentation can avoid the term "origin/master", and simply use "origin".
However, we need to make sure users have a properly set up "origin/HEAD", and at least in my case none of my remotes have set it up. Looking at the code, it seems:
git clone URL test
Is different than:
git init test
git remote add origin URL
git fetch origin
git checkout -b $favorite origin
In the latter there is no origin/HEAD, and I don't see why that should be the case.
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 3 lines · Junio C Hamano
I personally
do not like the word 'main' used as such, but the rest of the world seems to be moving in that direction,
I feel that 'main' is rather a rather dull and boring sort of word.
In that sense, it could be useful as the fall back for those who haven't yet got a clear view of what they want to call their first born. So I sort of support both views.
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
--
Philip
Hi Philip,
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
It might be easier to manage for _us_, the Git developers. But every user who initializes a repository and wants to push now needs to take the extra step to give their unnamed branch ("detached HEAD" is _still_ confusing new users!!!) a name.
That would be much more disruptive than choosing a "rather dull and boring" name instead of a rather racially-charged one.
And we promised to try to minimize the disruption to Git users.
Ciao,
Dscho
Hi Dscho,
Quoted 11 lines · Johannes Schindelin
Hi Philip,
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
It might be easier to manage for _us_, the Git developers. But every user who initializes a repository and wants to push now
Is this 'emerges fully formed' initialise & push really that common.
I'd be expecting a few add & commits prior to the push, so plenty of time for deciding and creating the chosen branch. At least that was the thought process...
Quoted 5 lines
needs to take the extra
step to give their unnamed branch("detached HEAD" is _still_ confusing
new users!!!) a name.
I'd only mentioned the detached head to keep the devs happy ;-) I'm quite happy with a "not on any named branch yet" type message for normal usage.
Quoted 3 lines
That would be much more disruptive than choosing a "rather dull and boring" name instead of a rather racially-charged one.
"Main" is fine, but Junio had mention say "Primary" as being more positive, but that is begging the question for the user. We should let them chose.
Hence using the not greatly inspiring 'main' as a starter offering would match that desire that the user should, ideally, make their own choice.
Quoted 2 lines
And we promised to try to minimize the disruption to Git users.
...but we haven't said 'it' is an ignorable issue. There's still a lot of old documentation and inertia to overcome.
Quoted 3 lines
Ciao,
Dscho
Philip
Hello,
It's worth noting that the word "slave" comes from the en_slav_ement of Slavs (the Slavic people of Eastern Europe).
I encourage the whole git team to really think about the changes you are making.
It was just reported to me that a professional friend of mine had confusion as to why,
after initializing a new repository, they couldn't navigate to the master branch of their repository.
I understand this is back-of-the-napkin type math but stay with me for one moment.
I also understand GitHub is not all of git users, but I just pulled the number to help me out here.
If GitHub has 40 million users but let's say half of them aren't active, so now we are at 20 million.
(Replace this number with how many actual users of git are out there.)
Let's even say half of them are on board and aware of this "harmless" change to a more "sensitive" doublespeak representation of the "master" copy/branch of the repo.
That leaves us with 10 million users of git that are either unaware or are not on board. Let's say it takes 3 minutes for a user to search on the web why exactly they can't
navigate to their "master" branch. That's 30 million minutes of time wasted, or about 57 man-YEARs of time wasted.... for what?
When do we put our foot down and say enough is enough, and not everything is offensive?
Again, please reconsider making this change towards doublespeak and consider the ramifications of how much actual human life & time will be wasted.
Kind Regards,
Peter
Quoted 23 lines · Johannes Schindelin
Hi Philip,
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
It might be easier to manage for _us_, the Git developers. But every user who initializes a repository and wants to push now needs to take the extra step to give their unnamed branch ("detached HEAD" is _still_ confusing new users!!!) a name.
That would be much more disruptive than choosing a "rather dull and boring" name instead of a rather racially-charged one.
And we promised to try to minimize the disruption to Git users.
Ciao,
Dscho
Signature · 1 line
Peter
Quoted 5 lines · Peter Hadlaw
That leaves us with 10 million users of git that are either unaware or are not on board. Let's say it takes 3 minutes for a user to search on the web why exactly they can't
navigate to their "master" branch. That's 30 million minutes of time wasted, or about 57 man-YEARs of time wasted.... for what?
That's (3 mins) probably about the same amount of time as most users waste on stack overflow for Git questions, or the old 'RTFM', for their problems in a typical week anyway.
3 mins out of a 35 hr week, over a 44 week x 25 year life is 1.3 ppm, unless you work too hard and too long, where it's an even lower ppm.
There are mechanism in this series for setting the default branch name.
--
Philip
There's still a responsibility for ~57 years worth of human life that doesn't actually need to be put at risk.
Someone forgetting how to rebase a branch in some given way and then having to search is their own responsibility.
On the other hand, this is a decision made on their behalf, without their consent, ... on everyone's behalf.
If you're not going to change the default without user input, are you going to ask the user for a default branch name?
Figure out the math and annoyance on that.
Quoted 19 lines · Philip Oakley
Quoted 5 lines · Peter Hadlaw
That leaves us with 10 million users of git that are either unaware or are not on board. Let's say it takes 3 minutes for a user to search on the web why exactly they can't
navigate to their "master" branch. That's 30 million minutes of time wasted, or about 57 man-YEARs of time wasted.... for what?That's (3 mins) probably about the same amount of time as most users waste on stack overflow for Git questions, or the old 'RTFM', for their problems in a typical week anyway.
3 mins out of a 35 hr week, over a 44 week x 25 year life is 1.3 ppm, unless you work too hard and too long, where it's an even lower ppm.
There are mechanism in this series for setting the default branch name.
--
Philip
Signature · 1 line
Peter
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
As has already been mentioned by Peff, I do not think that is a workable alternative, especially given that people are generally afraid of and easily get confused by being on a detached HEAD.
And there is no such thing as unborn detached HEAD. Existing versions of Git would not consider a $GIT_DIR that does not have any HEAD, which means a new repository created by such an "initially there is no branch" version of Git cannot be accessed by any existing versions of Git.
It raises the backward incompatibility of such an approach to a whole new level that is simply unmanageable, I am afraid.
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
As has already been mentioned by Peff, I do not think that is a workable alternative, especially given that people are generally afraid of and easily get confused by being on a detached HEAD.
Yes, our use of the technical phrase 'detached HEAD' is confusing, compared with the more pleasant 'not on any branch', or 'not at a branch tip'. Such is the curse of knowledge.
Quoted 6 lines
And there is no such thing as unborn detached HEAD. Existing versions of Git would not consider a $GIT_DIR that does not have any HEAD, which means a new repository created by such an "initially there is no branch" version of Git cannot be accessed by any existing versions of Git.
Isn't this, essentially, because there is no 'empty/null commit' that we (HEAD) could start at? There have been a few cases where I've been 'annoyed' that we're missing that. (rather than the orphan branch approach)
Quoted 3 lines
It raises the backward incompatibility of such an approach to a whole new level that is simply unmanageable, I am afraid.
OK, accepted.
Philip
Quoted 8 lines · Philip Oakley
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
Quoted 6 lines
Quoted 3 lines
As has already been mentioned by Peff, I do not think that is a workable alternative, especially given that people are generally afraid of and easily get confused by being on a detached HEAD.
Yes, our use of the technical phrase 'detached HEAD' is confusing, compared with the more pleasant 'not on any branch', or 'not at a branch tip'. Such is the curse of knowledge.
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
I wonder why Git didn't rather adopt "unnamed branch" or "nameless branch" to describe this mode of operation?
-- Sergey
Quoted 16 lines · Sergey Organov
Quoted 8 lines · Philip Oakley
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
Quoted 6 lines
Quoted 3 lines
As has already been mentioned by Peff, I do not think that is a workable alternative, especially given that people are generally afraid of and easily get confused by being on a detached HEAD.
Yes, our use of the technical phrase 'detached HEAD' is confusing, compared with the more pleasant 'not on any branch', or 'not at a branch tip'. Such is the curse of knowledge.
Quoted 6 lines
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
I wonder why Git didn't rather adopt "unnamed branch" or "nameless branch" to describe this mode of operation?
Given the ephemeral nature of branches they sound like good suggestion.
However I suspect "history" to be the "why" of the current 'detached head' usage.
Maybe it's a side reference to Nearly Headless Nick or other discussions of the time (aka lost in history)?
--
Philip
Quoted 17 lines · Philip Oakley
Quoted 16 lines · Sergey Organov
Quoted 14 lines · Philip Oakley
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Philip Oakley
An alternative in the other direction is to go with the 'not currently on any branch' (detached at nowhere) but then require users to deliberately create their first branch with their chosen name. This moves the 'backward incompatibility' to a different place, which may be easier to manage.
As has already been mentioned by Peff, I do not think that is a workable alternative, especially given that people are generally afraid of and easily get confused by being on a detached HEAD.
Yes, our use of the technical phrase 'detached HEAD' is confusing, compared with the more pleasant 'not on any branch', or 'not at a branch tip'. Such is the curse of knowledge.
Quoted 8 lines
Quoted 6 lines
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
I wonder why Git didn't rather adopt "unnamed branch" or "nameless branch" to describe this mode of operation?
Given the ephemeral nature of branches they sound like good suggestion.
Sure, so to me they sound even more natural in Git context than in any other VCS I'm aware of.
Quoted 5 lines
However I suspect "history" to be the "why" of the current 'detached head' usage.
Maybe it's a side reference to Nearly Headless Nick or other discussions of the time (aka lost in history)?
I do have a few commits at which HEAD has been detached, not once at some. Bloody they are.
-- Sergey
Quoted 3 lines · Sergey Organov
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
Aren't you confused about what "on a branch" means?
After either of these two operations, your HEAD may point at the same commit, but the former is on a branch (the master branch), and the latter is not.
git checkout master
git checkout master^0
The difference between these two states does *NOT* come from which commit HEAD points at.
The difference comes from what happens when you make a new commit starting from that state. The former (i.e. you are on a branch) grows the branch. The latter (i.e. you are not on a branch) does not grow any branch.
This is an unrelated trivia, but did anybody know that we were pretty much on the detached HEAD all the time for more than a month of early life of Git, until cad88fdf (git-init-db: set up the full default environment, 2005-05-30)?
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · Sergey Organov
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
Aren't you confused about what "on a branch" means?
I believe I'm not.
Quoted 10 lines
After either of these two operations, your HEAD may point at the same commit, but the former is on a branch (the master branch), and the latter is not.
git checkout master
git checkout master^0The difference between these two states does *NOT* come from which commit HEAD points at.
Sure.
Quoted 4 lines
The difference comes from what happens when you make a new commit starting from that state. The former (i.e. you are on a branch) grows the branch.
Sure.
Quoted 1 line
The latter (i.e. you are not on a branch) does not grow any branch.
That's one way of looking at it, resulting in this "detached HEAD" thingy that is too technical for the git user proper, I think. Moreover, it immediately raises the question: if it doesn't grow any branch, /what/ does it grow?
Another way of describing it, that I prefer, is that you /are/ on an /unnamed/ branch and new commits grow this particular /unnamed/ branch. No need not only for "detached", but even for "HEAD" to be known to the user to get the idea, I think.
Quoted 5 lines
This is an unrelated trivia, but did anybody know that we were pretty much on the detached HEAD all the time for more than a month of early life of Git, until
cad88fdf(git-init-db: set up the full default environment, 2005-05-30)?
I was not aware, and it seems that in my terminology it'd sound: "Git didn't have named branches until cad88fdf".
-- Sergey
Quoted 9 lines · Sergey Organov
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Sergey Organov
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
Aren't you confused about what "on a branch" means?
I believe I'm not.
Isn't this one of those "implementation detail" viewpoint arguments, combined with some incompleteness in various places.
From a naive english user perspective , 'on' a branch can also mean anywhere along a branch and not just at the tip. Being at a commit along a branch can be tricky to appreciate (that on/at distinction isn't immediately obvious..)
Quoted 11 lines
Quoted 10 lines
After either of these two operations, your HEAD may point at the same commit, but the former is on a branch (the master branch), and the latter is not.
git checkout master
git checkout master^0The difference between these two states does *NOT* come from which commit HEAD points at.
Sure.
From an implementation perspective one can go two ways, and we tell the user which way we went, even though, ultimately, we look at the same commit.
Though, for an unborn branch we don't have a null commit value (c.f. empty tree) to help in being 'detached at nowhere'.
Quoted 12 lines
Quoted 4 lines
The difference comes from what happens when you make a new commit starting from that state. The former (i.e. you are on a branch) grows the branch.
Sure.
Quoted 1 line
The latter (i.e. you are not on a branch) does not grow any branch.
That's one way of looking at it, resulting in this "detached HEAD" thingy that is too technical for the git user proper, I think. Moreover, it immediately raises the question: if it doesn't grow any branch, /what/ does it grow?
Quoted 4 lines
Another way of describing it, that I prefer, is that you /are/ on an /unnamed/ branch and new commits grow this particular /unnamed/ branch. No need not only for "detached", but even for "HEAD" to be known to the user to get the idea, I think.
I don't think we can start like this and continue with a commit on top of the orphaned 'unnamed' branch. (Not tried it though..)
Quoted 9 lines
Quoted 5 lines
This is an unrelated trivia, but did anybody know that we were pretty much on the detached HEAD all the time for more than a month of early life of Git, until
cad88fdf(git-init-db: set up the full default environment, 2005-05-30)?I was not aware, and it seems that in my terminology it'd sound: "Git didn't have named branches until
cad88fdf".-- Sergey
Quoted 26 lines · Philip Oakley
Quoted 9 lines · Sergey Organov
Quoted 6 lines · Junio C Hamano
Quoted 3 lines · Sergey Organov
To me "not on a branch [tip]" is also confusing, as in fact you are, as is easily seen after you perform a few commits, and now HEAD points directly to the tip of the branch (that has no other references).
Aren't you confused about what "on a branch" means?
I believe I'm not.
Isn't this one of those "implementation detail" viewpoint arguments, combined with some incompleteness in various places.
From a naive english user perspective , 'on' a branch can also mean anywhere along a branch and not just at the tip. Being at a commit along a branch can be tricky to appreciate (that on/at distinction isn't immediately obvious..)
Quoted 8 lines
Quoted 8 lines
After either of these two operations, your HEAD may point at the same commit, but the former is on a branch (the master branch), and the latter is not.
git checkout master
git checkout master^0
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
The difference between these two states does *NOT* come from which commit HEAD points at.
Sure.
From an implementation perspective one can go two ways, and we tell the user which way we went, even though, ultimately, we look at the same commit.
AFAIU, the only difference is that HEAD points to the commit directly in the case of "detached HEAD", while it points to the commit indirectly through the branch reference in the usual case.
Quoted 3 lines
Though, for an unborn branch we don't have a null commit value (c.f. empty tree) to help in being 'detached at nowhere'.
We can pretend we have a null commit for the sake of regularity, even though Git implementation has none.
Actually, it looks like a few things would be easier if Git got the "Adam" commit that is the ultimate final parent of everything in the first place, but it didn't.
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
The difference comes from what happens when you make a new commit starting from that state. The former (i.e. you are on a branch) grows the branch.
Sure.
Quoted 1 line
The latter (i.e. you are not on a branch) does not grow any branch.
That's one way of looking at it, resulting in this "detached HEAD" thingy that is too technical for the git user proper, I think. Moreover, it immediately raises the question: if it doesn't grow any branch, /what/ does it grow?
Quoted 6 lines
Quoted 4 lines
Another way of describing it, that I prefer, is that you /are/ on an /unnamed/ branch and new commits grow this particular /unnamed/ branch. No need not only for "detached", but even for "HEAD" to be known to the user to get the idea, I think.
I don't think we can start like this and continue with a commit on top of the orphaned 'unnamed' branch. (Not tried it though..)
I rather believe we can, no problems, and that's why "detached HEAD" behaves exactly as unnamed branch would.
To make it obvious "detached HEAD" is in fact a subset of the usual case, imagine that "detached HEAD" is rather first implemented by pointing to a branch reference with a hidden name that in turn points to the commit, and then this "incognito branch reference" is optimized-out as being invisible anyway, so HEAD now points to the commit itself.
-- Sergey Organov
Quoted 12 lines · Sergey Organov
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
The latter (i.e. you are not on a branch) does not grow any branch.
That's one way of looking at it, resulting in this "detached HEAD" thingy that is too technical for the git user proper, I think. Moreover, it immediately raises the question: if it doesn't grow any branch, /what/ does it grow?
Quoted 6 lines
Quoted 4 lines
Another way of describing it, that I prefer, is that you /are/ on an /unnamed/ branch and new commits grow this particular /unnamed/ branch. No need not only for "detached", but even for "HEAD" to be known to the user to get the idea, I think.
I don't think we can start like this and continue with a commit on top of the orphaned 'unnamed' branch. (Not tried it though..)
Quoted 9 lines
I rather believe we can, no problems, and that's why "detached HEAD" behaves exactly as unnamed branch would.
To make it obvious "detached HEAD" is in fact a subset of the usual case, imagine that "detached HEAD" is rather first implemented by pointing to a branch reference with a hidden name that in turn points to the commit, and then this "incognito branch reference" is optimized-out as being invisible anyway, so HEAD now points to the commit itself.
Thinking about some options...
After a git init: We can hack HEAD to "ref: refs/heads/" (i.e. a symref to an unnamed branch) and git status will report "No commits yet". My PS1 will report the current branch as "()" (i.e. an empty name).
However,git branch reports "Failed to resolve HEAD as a valid ref.", and git commit reports "cannot lock ref 'HEAD': there is a non-empty directory '.git/refs/heads/' blocking reference 'refs/heads/'".
So, there could be the option to detect that unnamed ref state (no characters after the final "/") without going "Fatal:".
However there is still the potential difficulty that after the first commit on that unnamed branch we would have the difficult choice of:
- either keeping that unnamed ref/branch symref, and have nowhere to hold the new commit name (oid), because HEAD is already acting as the place holder for the symref,
- or we have to lose the place holder symref and place the new commit oid into HEAD, leaving us back at the regular "detached head", but for an as yet unnamed orphan branch.
(tested on Windows[1])
For the second case we would still need to ensure that protections are in place to avoid loosing those detached commits if the user switches/checks out to new branch based on some other oid. (for that to happen then that checkout oid must be somewhere in the unnamed branch, but the latest tip commits should need checking to prevent unexpected loss - the current warning may not be enough...)
At the moment there is a lot of 'lock-in' for the status quo, and the alternative may not be any better, and have some backward compatibility issues, though those may be overstated, depending on how repos are being 'shared'.
Philip
[1]
phili@Philip-Win10 MINGW64 /c/git-sdk-64/usr/src/unnamed ()
$ git version git version 2.29.2.windows.2
Quoted 10 lines · Sergey Organov
Quoted 1 line · Junio C Hamano
The latter (i.e. you are not on a branch) does not grow any branch.
That's one way of looking at it, resulting in this "detached HEAD" thingy that is too technical for the git user proper, I think. Moreover, it immediately raises the question: if it doesn't grow any branch, /what/ does it grow?
Quoted 4 lines
Another way of describing it, that I prefer, is that you /are/ on an /unnamed/ branch and new commits grow this particular /unnamed/ branch. No need not only for "detached", but even for "HEAD" to be known to the user to get the idea, I think.
This is precisely what it is conceptually.
And there's absolutely no need for the user to know what HEAD is behind the curtains, especially since they can just use @, and think of it as "the current branch".
It is clearly a branch, for example you can do "git push origin @:my-fix".
Cheers.
Signature · 1 line
Felipe Contreras
Quoted 1 line · Felipe Contreras
It is clearly a branch, for example you can do "git push origin @:my-fix".
Hmm, you can also do "git push origin c2f3bf071e:maintenance", but it does not make a bare object name a branch.
At least I doubt the "clearly" part of your statement. There might be a better example to support the above claim, but this one is not.
Quoted 11 lines · Eric W. Biederman
Instead of having a fixed name across all repos for the initially created branch can we instead use the directory name of the repo for the branch name?
Advantages:
- The branch name that is somewhat meaningful to the creator of the git repo.
I have at least two repos where I wound up doing this by hand. So at least for me it is something I am doing anyway.
Example: this would make the main branch in a new git.git repository default to "git". However, we would be free to switch to some other workflow-specific name like "stable".
Quoted 5 lines
- Tools can not hard code the name of an initially created branch and expect it to work.
This moves us farther from the realm of people assuming incorrectly that there is something special about the branch created by default.
What's especially nice about this is that a repository's local basename and the URL at which it gets published do not always coincide. So scripts designed to be robust would be more likely to use commands like "git branch --show-current" instead of trying to guess using the new rule.
That said, if I put myself in the shoes of such a script author for a moment, I'm likely to be irritated. What started as a static string now becomes something dynamic. If I put myself in the shoes of someone who has *inherited* a script (a testsuite, maybe), I'm likely to be even more irritated.
For testsuites, one can buy time by setting init.defaultBranch, but not for other scripts.
Are there things we can do to make a script author's life easier?
Today if I want to look up a remote repository's default branch, the best I can do is
git ls-remote --symref origin HEAD
The output is not as easy to parse as I'd like: it's split between two lines and has multiple fields on each line. Worse, it is slow, since it scans all refs instead of just the ref I wanted. Even worse, if another ref in the remote repository ends with /HEAD (e.g., refs/remotes/someremote/HEAD), it prints that, too.
If I could do something like
git ls-remote --format='%(symref)' --exact-match origin HEAD
(using for-each-ref style formats, and allowing exact matching) then that would be helpful.
In general, this aspect of a less deterministic first branchname is appealing; it would result in improving the quality of the ecosystem of tools built around Git. This is what I like most about this proposal.
[...]
Quoted 3 lines
At least for my usage main is a pretty huge misnomer as I barely use the branch with the master. Renaming my unused branch main implies that I am using the tool wrong.
Is that because "master" is inherited from your upstream? Which branch would you want people to check out by default when they clone from your repo?
For what it's worth:
- I find this proposal really tempting, and have liked it since the moment gitster brought it up on #git-devel. The main reason I haven't brought it up since then is that I didn't have a patch implementing it. :)
- That said, a fixed string as default would be fine with me, too.
Thanks,
Jonathan
Quoted 5 lines · Jonathan Nieder
That said, if I put myself in the shoes of such a script author for a moment, I'm likely to be irritated. What started as a static string now becomes something dynamic. If I put myself in the shoes of someone who has *inherited* a script (a testsuite, maybe), I'm likely to be even more irritated.
It is conceptually really nice to say that we do not use words like 'master' and 'main' that are 'meaningless' in the context of thinking about the workflow used for the project and instead pick the word the end user chose to call (some aspect of) the project (i.e. the name of the directory to host its working tree). It however is much harder to defend the design in real life because it can lead to the irritations you mention.
Quoted 1 line
Are there things we can do to make a script author's life easier?
It largely depends on what "specialness" of 'master' branch the script is interested in, isn't it?
Quoted 6 lines
Today if I want to look up a remote repository's default branch, the best I can do is
git ls-remote --symref origin HEADThe output is not as easy to parse as I'd like:...
In a sense, these follower repositories are easier to work with.
You have refs/remotes/origin/HEAD that indicates what the owner of the local repository considers of the most significance; it is initialized to match what the remote had pointed with its HEAD when the repository was cloned, but the local user can repoint it when the local interest diverge from that of the remote's. And you do not need to talk over the network with ls-remote to find that out (actually asking ls-remote may actively be wrong after the local user repointed it); you only need to ask 'git symbolic-ref' which is totally local.