* Re: Reference the master/main branch with @{m}
2023-04-24 15:11 Reference the master/main branch with @{m} Xavier Roche
@ 2023-04-24 15:45 ` Felipe Contreras
0 siblings, 0 replies; 2+ messages in thread
From: Felipe Contreras @ 2023-04-24 15:45 UTC (permalink / raw)
To: Xavier Roche, git
Xavier Roche wrote:
> With git, you can reference the upstream branch with the @{upstream}
> or @{u} shorthand
> (https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches)
>
> With master/main branch varying among repositories, it would be handy
> to have a "main/master" reference, such as @{main} or @{m}
>
> Would that make sense?
No, it would not make sense.
The `@{upstream}` mark is itself a shorthand for `HEAD@{upstream}`, so it
depends on the value of `HEAD`. For example if the current branch is is
"hot-fix-1", "@{upstream}" could be "master", but if the current branch is
"feature-1", "@{upstream}" could be "dev": "hot-fix-1@{upstream}" !=
"feature-1@{upstream}".
`HEAD@{m}` does not make sense, because it would be the same for all branches.
We could have a "DEFAULT" pseudo-branch, or maybe even "default", but this is
not necessary, because that's something that you can already achieve.
Your personal local repository does not have to mirror the remote repository.
You can have a local "default" branch whose upstream branch is "master" or
"main" (depending on the remote).
This is what I do. If I clone a repository that uses "main", I simply rename
the default branch in my local repository to "master".
Arguably this is something that `git clone` should do by default: if I have
configured `init.defaultbranch=master`, `git clone` should do `git clone -b
master` by default.
Either way, doing `git branch -m master` in the tiny minority of repos that
don't use "master" as the default branch seems like a marginal effort to me.
Cheers.
--
Felipe Contreras
^ permalink raw reply [flat|nested] 2+ messages in thread