* BUG: git log on bare repository fails if the default branch is not called master @ 2022-06-03 14:22 Ian Molton 2022-06-03 14:40 ` AW: " stefan.naewe 0 siblings, 1 reply; 5+ messages in thread From: Ian Molton @ 2022-06-03 14:22 UTC (permalink / raw) To: git; +Cc: Ian Molton Hi, Please CC me in replies, I'm not on the list. I've noticed that git log assumes the default branch is master, even if it doesn't exist... My latest repo has it set to "mainline" and all was well until I pushed it to a bare repo on my server. Expectation: If I run git log in the bare repo, it should log the default (or only!) branch. Reality: git log # fatal: your current branch 'master' does not have any commits yet -Ian ^ permalink raw reply [flat|nested] 5+ messages in thread
* AW: git log on bare repository fails if the default branch is not called master 2022-06-03 14:22 BUG: git log on bare repository fails if the default branch is not called master Ian Molton @ 2022-06-03 14:40 ` stefan.naewe 2022-06-03 18:06 ` Ian Molton 0 siblings, 1 reply; 5+ messages in thread From: stefan.naewe @ 2022-06-03 14:40 UTC (permalink / raw) To: git-ian, git > -----Ursprüngliche Nachricht----- > Von: Ian Molton <git-ian@mnementh.co.uk> > Gesendet: Freitag, 3. Juni 2022 16:22 > An: git@vger.kernel.org > Cc: Ian Molton <git-ian@mnementh.co.uk> > Betreff: BUG: git log on bare repository fails if the default branch is not called > master > > Hi, > > Please CC me in replies, I'm not on the list. > > I've noticed that git log assumes the default branch is master, even if it doesn't > exist... > > My latest repo has it set to "mainline" and all was well until I pushed it to a bare > repo on my server. > > Expectation: > > If I run > > git log > > in the bare repo, it should log the default (or only!) branch. > > Reality: > > git log > # fatal: your current branch 'master' does not have any commits yet I bet the HEAD file in your bare repository points to refs/heads/master... Stefan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: AW: git log on bare repository fails if the default branch is not called master 2022-06-03 14:40 ` AW: " stefan.naewe @ 2022-06-03 18:06 ` Ian Molton 2022-06-03 18:56 ` Junio C Hamano 2022-06-04 0:50 ` Chris Torek 0 siblings, 2 replies; 5+ messages in thread From: Ian Molton @ 2022-06-03 18:06 UTC (permalink / raw) To: stefan.naewe, git-ian, git On 03/06/2022 15:40, stefan.naewe@atlas-elektronik.com wrote: > I bet the HEAD file in your bare repository points to refs/heads/master... Possibly, but why? the only thiong that ever happened to was that I pushed my code into it, from a repo that used mainline (not master). Why does a bare repo even have a HEAD file? (genuinely curious). It seems like it'd be best to create it when it's first pushed to? then it'd match whatever is used in the pushing repo... -Ian ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: AW: git log on bare repository fails if the default branch is not called master 2022-06-03 18:06 ` Ian Molton @ 2022-06-03 18:56 ` Junio C Hamano 2022-06-04 0:50 ` Chris Torek 1 sibling, 0 replies; 5+ messages in thread From: Junio C Hamano @ 2022-06-03 18:56 UTC (permalink / raw) To: Ian Molton; +Cc: stefan.naewe, git Ian Molton <git-ian@mnementh.co.uk> writes: > Why does a bare repo even have a HEAD file? (genuinely curious). It > seems like it'd be best to create it when it's first pushed to? then > it'd match whatever is used in the pushing repo... There indeed are things that have no reason to exist in a bare repository, but HEAD is not among them. It should have HEAD to indicate what the owner of the repository considers the primary branch to follow the project hosted there. Anybody cloning from that bare repository will learn the name of what HEAD points at and that branch gets checked out when "clone" finishes its job. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: AW: git log on bare repository fails if the default branch is not called master 2022-06-03 18:06 ` Ian Molton 2022-06-03 18:56 ` Junio C Hamano @ 2022-06-04 0:50 ` Chris Torek 1 sibling, 0 replies; 5+ messages in thread From: Chris Torek @ 2022-06-04 0:50 UTC (permalink / raw) To: Ian Molton; +Cc: stefan.naewe, Git List On Fri, Jun 3, 2022 at 2:49 PM Ian Molton <git-ian@mnementh.co.uk> wrote: > Why does a bare repo even have a HEAD file? All repositories (bare or not) *must* have a `HEAD` setting. This contains the name of the current branch, or, if the repository is in detached-HEAD mode, the hash ID of the current commit. In a new repository (bare or not), there are no commits, so there cannot be a *current commit*. A branch name is also constrained to contain a valid hash ID, and there are no valid hash IDs, so there are no branch names. Nonetheless you are still "on" some branch: it's just an *unborn* (or "orphan") branch. In this mode, making a commit causes the branch name to spring into existence. So if your new empty repository is "on" `master`, the next `git commit` you run in that repository will create the branch `master`. As it's a bare repository, you probably will never run `git commit` there. As Junio noted, the current branch is the branch name that a Git repository "recommends" to another Git that is performing a `git clone` operation. This makes it the "default branch". Normally we'd use `git switch` or `git checkout` to change the *current* branch and thus change the default branch, but in a bare repository, we cannot do this (at least not without supplying a temporary working tree), so you must either use `git symbolic-ref` or resort to direct writing to `.git/HEAD` to change the default branch in the bare repo. The new `init.defaultBranch` configuration setting controls the name of the nonexistent branch you're on in a newly created repository. Given your setup you may wish to configure yours to be `main`. Last, note that you can re-create this "we are now on a branch that does not exist" status at any time you like (in an ordinary non-bare repository) using `git switch` or `git checkout` with the `--orphan` argument. (Watch out, there's a subtle difference between these two commands: use `git status` to observe the index state before committing.) Chris ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-04 0:50 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-06-03 14:22 BUG: git log on bare repository fails if the default branch is not called master Ian Molton 2022-06-03 14:40 ` AW: " stefan.naewe 2022-06-03 18:06 ` Ian Molton 2022-06-03 18:56 ` Junio C Hamano 2022-06-04 0:50 ` Chris Torek
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).