{"thread":{"id":"57951","subject":"BUG: git log on bare repository fails if the default branch is not called master","startedAt":"2022-06-03T14:22:16Z","lastAt":"2022-06-04T00:50:51Z","messageCount":5,"participants":["Ian Molton","stefan.naewe@atlas-elektronik.com","Junio C Hamano","Chris Torek"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"456583","messageId":"a1830e79-9503-3fd9-8c50-a2856206e219@mnementh.co.uk","threadId":"57951","inReplyTo":null,"subject":"BUG: git log on bare repository fails if the default branch is not called master","fromName":"Ian Molton","fromEmail":"git-ian@mnementh.co.uk","sentAt":"2022-06-03T14:22:04Z","receivedAt":"2022-06-03T14:22:16Z","isPatch":false,"sender":{"key":"git-ian@mnementh.co.uk","avatar":null},"body":"Hi,\n\nPlease CC me in replies, I'm not on the list.\n\nI've noticed that git log assumes the default branch is master, even if\nit doesn't exist...\n\nMy latest repo has it set to \"mainline\" and all was well until I pushed\nit to a bare repo on my server.\n\nExpectation:\n\nIf I run\n\ngit log\n\nin the bare repo, it should log the default (or only!) branch.\n\nReality:\n\ngit log\n# fatal: your current branch 'master' does not have any commits yet\n\n-Ian\n"},{"id":"456586","messageId":"48bcd99afbca4c73b938c3ed4e104c64@atlas-elektronik.com","threadId":"57951","inReplyTo":"a1830e79-9503-3fd9-8c50-a2856206e219@mnementh.co.uk","subject":"AW: git log on bare repository fails if the default branch is not called master","fromName":"","fromEmail":"stefan.naewe@atlas-elektronik.com","sentAt":"2022-06-03T14:40:22Z","receivedAt":"2022-06-03T14:40:57Z","isPatch":false,"sender":{"key":"stefan.naewe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4468?v=4"},"body":"\n\n> -----Ursprüngliche Nachricht-----\n> Von: Ian Molton <git-ian@mnementh.co.uk>\n> Gesendet: Freitag, 3. Juni 2022 16:22\n> An: git@vger.kernel.org\n> Cc: Ian Molton <git-ian@mnementh.co.uk>\n> Betreff: BUG: git log on bare repository fails if the default branch is not called\n> master\n> \n> Hi,\n> \n> Please CC me in replies, I'm not on the list.\n> \n> I've noticed that git log assumes the default branch is master, even if it doesn't\n> exist...\n> \n> My latest repo has it set to \"mainline\" and all was well until I pushed it to a bare\n> repo on my server.\n> \n> Expectation:\n> \n> If I run\n> \n> git log\n> \n> in the bare repo, it should log the default (or only!) branch.\n> \n> Reality:\n> \n> git log\n> # fatal: your current branch 'master' does not have any commits yet\n\nI bet the HEAD file in your bare repository points to refs/heads/master...\n\n\nStefan\n"},{"id":"456601","messageId":"9df6c37e-4c43-7697-0562-c49d4fa5b38f@mnementh.co.uk","threadId":"57951","inReplyTo":"48bcd99afbca4c73b938c3ed4e104c64@atlas-elektronik.com","subject":"Re: AW: git log on bare repository fails if the default branch is not called master","fromName":"Ian Molton","fromEmail":"git-ian@mnementh.co.uk","sentAt":"2022-06-03T18:06:28Z","receivedAt":"2022-06-03T18:22:11Z","isPatch":false,"sender":{"key":"git-ian@mnementh.co.uk","avatar":null},"body":"On 03/06/2022 15:40, stefan.naewe@atlas-elektronik.com wrote:\n\n> I bet the HEAD file in your bare repository points to refs/heads/master...\n\nPossibly, but why? the only thiong that ever happened to was that I\npushed my code into it, from a repo that used mainline (not master).\n\nWhy does a bare repo even have a HEAD file? (genuinely curious). It\nseems like it'd be best to create it when it's first pushed to? then\nit'd match whatever is used in the pushing repo...\n\n-Ian\n"},{"id":"456624","messageId":"xmqqmtetfuer.fsf@gitster.g","threadId":"57951","inReplyTo":"9df6c37e-4c43-7697-0562-c49d4fa5b38f@mnementh.co.uk","subject":"Re: AW: git log on bare repository fails if the default branch is not called master","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-06-03T18:56:12Z","receivedAt":"2022-06-03T18:56:23Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ian Molton <git-ian@mnementh.co.uk> writes:\n\n> Why does a bare repo even have a HEAD file? (genuinely curious). It\n> seems like it'd be best to create it when it's first pushed to? then\n> it'd match whatever is used in the pushing repo...\n\nThere indeed are things that have no reason to exist in a bare\nrepository, but HEAD is not among them.\n\nIt should have HEAD to indicate what the owner of the repository\nconsiders the primary branch to follow the project hosted there.\nAnybody cloning from that bare repository will learn the name of\nwhat HEAD points at and that branch gets checked out when \"clone\"\nfinishes its job.\n\n"},{"id":"456650","messageId":"CAPx1GvcxtvowiLkmihZQX+8-=+5c-zJT3M7OmO_BxO4qqqAMyA@mail.gmail.com","threadId":"57951","inReplyTo":"9df6c37e-4c43-7697-0562-c49d4fa5b38f@mnementh.co.uk","subject":"Re: AW: git log on bare repository fails if the default branch is not called master","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2022-06-04T00:50:36Z","receivedAt":"2022-06-04T00:50:51Z","isPatch":false,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Fri, Jun 3, 2022 at 2:49 PM Ian Molton <git-ian@mnementh.co.uk> wrote:\n> Why does a bare repo even have a HEAD file?\n\nAll repositories (bare or not) *must* have a `HEAD` setting.  This\ncontains the name of the current branch, or, if the repository is\nin detached-HEAD mode, the hash ID of the current commit.\n\nIn a new repository (bare or not), there are no commits, so there\ncannot be a *current commit*. A branch name is also constrained to\ncontain a valid hash ID, and there are no valid hash IDs, so there\nare no branch names.  Nonetheless you are still \"on\" some branch:\nit's just an *unborn* (or \"orphan\") branch.\n\nIn this mode, making a commit causes the branch name to spring\ninto existence.  So if your new empty repository is \"on\" `master`,\nthe next `git commit` you run in that repository will create the\nbranch `master`. As it's a bare repository, you probably will\nnever run `git commit` there.\n\nAs Junio noted, the current branch is the branch name that a Git\nrepository \"recommends\" to another Git that is performing a `git\nclone` operation.  This makes it the \"default branch\". Normally\nwe'd use `git switch` or `git checkout` to change the *current*\nbranch and thus change the default branch, but in a bare\nrepository, we cannot do this (at least not without supplying a\ntemporary working tree), so you must either use `git symbolic-ref`\nor resort to direct writing to `.git/HEAD` to change the default\nbranch in the bare repo.\n\nThe new `init.defaultBranch` configuration setting controls the\nname of the nonexistent branch you're on in a newly created\nrepository. Given your setup you may wish to configure yours to\nbe `main`.\n\nLast, note that you can re-create this \"we are now on a branch\nthat does not exist\" status at any time you like (in an ordinary\nnon-bare repository) using `git switch` or `git checkout` with the\n`--orphan` argument. (Watch out, there's a subtle difference\nbetween these two commands: use `git status` to observe the\nindex state before committing.)\n\nChris\n"}]}