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

Re: Reference the master/main branch with @{m}

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 24, 2023, 15:45 UTC
Message-ID
<6446a415925b2_393129470@chronos.notmuch>
In-Reply-To
<CAE9vp3+_PB0_rA81eWVCF=iXnWjrUVY=1G3=1JPUbcaw2u95Rg@mail.gmail.com>
Xavier Roche wrote:
Show 8 quoted lines
> 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
Previous: Xavier Roche
Message 2 of 2 in “Reference the master/main branch with @{m}”
  1. Xavier RocheApr 24, 2023
  2. Felipe ContrerasApr 24, 2023

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.