{"thread":{"id":"46591","subject":"Bug: `git remote show <remote>` reports different HEAD branch than refs/remotes/<remote>/HEAD","startedAt":"2017-08-15T14:26:45Z","lastAt":"2017-08-15T21:59:53Z","messageCount":4,"participants":["Jason Karns","Igor Djordjevic","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"326401","messageId":"CAKNmmv3_K4gB6FbcmAjXyviMbU2Ts7Rh7txkOof+-36rF_1+Gw@mail.gmail.com","threadId":"46591","inReplyTo":null,"subject":"Bug: `git remote show <remote>` reports different HEAD branch than refs/remotes/<remote>/HEAD","fromName":"Jason Karns","fromEmail":"jason.karns@gmail.com","sentAt":"2017-08-15T14:26:19Z","receivedAt":"2017-08-15T14:26:45Z","isPatch":false,"sender":{"key":"jason.karns@gmail.com","avatar":"https://gravatar.com/avatar/c86e80bb1929ad0ea739f79f04d349adfa550d010fde1bd1ea413b6c277e850f?d=mp&s=160"},"body":"I have a git repo that shows a different branch in\n`.git/refs/remotes/origin/HEAD` than is reported by `git remote show\norigin`.\n\nThe branch is `github-rename` in refs/remotes/origin/HEAD, but shows\n`master` in output of git-remote-show\n\n```\n$ cat .git/refs/remotes/origin/HEAD\nref: refs/remotes/origin/github-rename\n\n$ git remote show origin\n* remote origin\n  Fetch URL: git@XXXX.git\n  Push  URL: git@XXXX.git\n  HEAD branch: master\n  Remote branches:\n    github-rename     tracked\n    master            tracked\n    qa                tracked\n    refactor-test     tracked\n  Local branches configured for 'git pull':\n    github-rename merges with remote github-rename\n    master        merges with remote master\n  Local refs configured for 'git push':\n    github-rename pushes to github-rename (up to date)\n    master        pushes to master        (up to date)\n```\n\ngit version 2.14.1\n\n\nBackground:\n\nPrior to my repo being cloned, the default branch was configured to be\n`some-random-branch` on github. My repo was cloned and the HEAD branch\nwas set to `some-random-branch` correctly (in `refs/`). However,\ngit-remote-show reported `master` as the HEAD branch.\n\nLater, `some-random-branch` was deleted from the remote. It _remained_\nas the HEAD branch locally according to `refs/`.\n\nIn order to test the remote-show command, I changed the HEAD branch to\na branch that actually existed by running `git remote set-head origin\ngithub-rename`. It changed the HEAD branch in `refs/` but remote-show\ncontinues to report `master` as the remote's HEAD.\n\n\nThanks,\nJason Karns\n"},{"id":"326411","messageId":"bad7dafc-247c-bf5e-8cfd-5445badeef1c@gmail.com","threadId":"46591","inReplyTo":"CAKNmmv3_K4gB6FbcmAjXyviMbU2Ts7Rh7txkOof+-36rF_1+Gw@mail.gmail.com","subject":"Re: Bug: `git remote show <remote>` reports different HEAD branch than refs/remotes/<remote>/HEAD","fromName":"Igor Djordjevic","fromEmail":"igor.d.djordjevic@gmail.com","sentAt":"2017-08-15T17:09:03Z","receivedAt":"2017-08-15T17:09:13Z","isPatch":false,"sender":{"key":"igor.d.djordjevic@gmail.com","avatar":null},"body":"Hi Jason,\n\nOn 15/08/2017 16:26, Jason Karns wrote:\n> I have a git repo that shows a different branch in\n> `.git/refs/remotes/origin/HEAD` than is reported by `git remote show\n> origin`.\n> \n> The branch is `github-rename` in refs/remotes/origin/HEAD, but shows\n> `master` in output of git-remote-show\n> \n> ```\n> $ cat .git/refs/remotes/origin/HEAD\n> ref: refs/remotes/origin/github-rename\n> \n> $ git remote show origin\n> * remote origin\n>   Fetch URL: git@XXXX.git\n>   Push  URL: git@XXXX.git\n>   HEAD branch: master\n>   Remote branches:\n>     github-rename     tracked\n>     master            tracked\n>     qa                tracked\n>     refactor-test     tracked\n>   Local branches configured for 'git pull':\n>     github-rename merges with remote github-rename\n>     master        merges with remote master\n>   Local refs configured for 'git push':\n>     github-rename pushes to github-rename (up to date)\n>     master        pushes to master        (up to date)\n> ```\n> \n> git version 2.14.1\n> \n> \n> Background:\n> \n> Prior to my repo being cloned, the default branch was configured to be\n> `some-random-branch` on github. My repo was cloned and the HEAD branch\n> was set to `some-random-branch` correctly (in `refs/`). However,\n> git-remote-show reported `master` as the HEAD branch.\n> \n> Later, `some-random-branch` was deleted from the remote. It _remained_\n> as the HEAD branch locally according to `refs/`.\n> \n> In order to test the remote-show command, I changed the HEAD branch to\n> a branch that actually existed by running `git remote set-head origin\n> github-rename`. It changed the HEAD branch in `refs/` but remote-show\n> continues to report `master` as the remote's HEAD. \n\nI am no expert here, but reading the docs, it seems like you may have \nwrong expectations.\n\nDocumentation for \"git remote set-head\"[1] explains that this command \nis used to set default remote branch (locally), where later you can \nuse remote name only to specify that specific (remote) branch instead.\n\nExample shows that for remote named \"origin\", if you set default \nbranch name to \"master\" (actually being \"origin/master\" locally), \nthen whenever you want to type \"origin/master\", you can type \"origin\" \nonly instead (set default branch name is implied).\n\nFor the given example, that is what you can see inside \n\"refs/remotes/origin/HEAD\", being set to \"refs/remotes/origin/master\".\n\nSo it is something _you_ set _locally_ to aid you in working with the \nremote repository.\n\nOn the other hand, what \"git remote show\" outputs for HEAD is a name \nof actually checked-out branch inside that remote repository - it`s \nwhat`s stored inside HEAD file of the remote repository root.\n\nSo it is something set on the _remote_ end, you can`t influence it \nfrom your local repository.\n\nWhat you _could_ do in your specific case, as you mention using \nGitHub, is following their help page for \"setting the default \nbranch\"[2] for your GitHub repository (which you track locally as \n\"origin\") to \"github-rename\".\n\n(in general, non-GitHub repository case, one could usually run there \neither `git checkout github-rename`, if it`s not a bare repository, \nor `git symbolic-ref HEAD refs/heads/github-rename`, if it`s a bare \nrepository)\n\nAfterwards, running `git remote show origin` inside your local \nrepository should output \"github-rename\" as HEAD value, as desired.\n\np.s. To set your default remote branch locally to checked-out branch \non the remote end automatically, you can use `git remote set-head \norigin --auto`, as documented[1]. It will inspect what`s inside \n\"HEAD\" of the remote named \"origin\", and update your local \n\"refs/remotes/origin/HEAD\" accordingly.\n\n[1] https://git-scm.com/docs/git-remote#git-remote-emset-headem\n[2] https://help.github.com/articles/setting-the-default-branch/\n\nRegards,\nBuga\n"},{"id":"326421","messageId":"CAKNmmv3_rFNDDFVEeShAb3mEMOBL4z=oZXP8Df72D44stB_7BA@mail.gmail.com","threadId":"46591","inReplyTo":"bad7dafc-247c-bf5e-8cfd-5445badeef1c@gmail.com","subject":"Re: Bug: `git remote show <remote>` reports different HEAD branch than refs/remotes/<remote>/HEAD","fromName":"Jason Karns","fromEmail":"jason.karns@gmail.com","sentAt":"2017-08-15T17:58:38Z","receivedAt":"2017-08-15T17:59:07Z","isPatch":false,"sender":{"key":"jason.karns@gmail.com","avatar":"https://gravatar.com/avatar/c86e80bb1929ad0ea739f79f04d349adfa550d010fde1bd1ea413b6c277e850f?d=mp&s=160"},"body":"On Tue, Aug 15, 2017 at 1:09 PM, Igor Djordjevic\n<igor.d.djordjevic@gmail.com> wrote:\n> Hi Jason,\n>\n> On 15/08/2017 16:26, Jason Karns wrote:\n>> I have a git repo that shows a different branch in\n>> `.git/refs/remotes/origin/HEAD` than is reported by `git remote show\n>> origin`.\n>>\n>> The branch is `github-rename` in refs/remotes/origin/HEAD, but shows\n>> `master` in output of git-remote-show\n>>\n>> ```\n>> $ cat .git/refs/remotes/origin/HEAD\n>> ref: refs/remotes/origin/github-rename\n>>\n>> $ git remote show origin\n>> * remote origin\n>>   Fetch URL: git@XXXX.git\n>>   Push  URL: git@XXXX.git\n>>   HEAD branch: master\n>>   Remote branches:\n>>     github-rename     tracked\n>>     master            tracked\n>>     qa                tracked\n>>     refactor-test     tracked\n>>   Local branches configured for 'git pull':\n>>     github-rename merges with remote github-rename\n>>     master        merges with remote master\n>>   Local refs configured for 'git push':\n>>     github-rename pushes to github-rename (up to date)\n>>     master        pushes to master        (up to date)\n>> ```\n>>\n>> git version 2.14.1\n>>\n>>\n>> Background:\n>>\n>> Prior to my repo being cloned, the default branch was configured to be\n>> `some-random-branch` on github. My repo was cloned and the HEAD branch\n>> was set to `some-random-branch` correctly (in `refs/`). However,\n>> git-remote-show reported `master` as the HEAD branch.\n>>\n>> Later, `some-random-branch` was deleted from the remote. It _remained_\n>> as the HEAD branch locally according to `refs/`.\n>>\n>> In order to test the remote-show command, I changed the HEAD branch to\n>> a branch that actually existed by running `git remote set-head origin\n>> github-rename`. It changed the HEAD branch in `refs/` but remote-show\n>> continues to report `master` as the remote's HEAD.\n>\n> I am no expert here, but reading the docs, it seems like you may have\n> wrong expectations.\n>\n> Documentation for \"git remote set-head\"[1] explains that this command\n> is used to set default remote branch (locally), where later you can\n> use remote name only to specify that specific (remote) branch instead.\n>\n> Example shows that for remote named \"origin\", if you set default\n> branch name to \"master\" (actually being \"origin/master\" locally),\n> then whenever you want to type \"origin/master\", you can type \"origin\"\n> only instead (set default branch name is implied).\n>\n> For the given example, that is what you can see inside\n> \"refs/remotes/origin/HEAD\", being set to \"refs/remotes/origin/master\".\n>\n> So it is something _you_ set _locally_ to aid you in working with the\n> remote repository.\n\n\nCool, this is all to my expectations.\n\n>\n> On the other hand, what \"git remote show\" outputs for HEAD is a name\n> of actually checked-out branch inside that remote repository - it`s\n> what`s stored inside HEAD file of the remote repository root.\n>\n> So it is something set on the _remote_ end, you can`t influence it\n> from your local repository.\n\n\nSo _this_ is not what I expected. Thanks for clarifying.\n\nConsidering that a fresh clone replicates the remote's default branch\nas the local default for that remote, I wager (in the majority of\ncases) that these two are the same. It would seem that what I would\nlike in this case is a feature change to git-remote-show to show both\nthe locally-configured and remote-configured defaults for the given\nremote (similar in spirit to how git-remote-show already shows local\nvs remote information: branches and their configurations for\npush/pull).\n\nSuch a feature would be the \"read\" side of the remote set-head\ncommand, and also be useful for highlighting cases where the local and\nremote defaults do not match.\n\nIf I might suggest adding \"Local default branch: xxx\" to the\nremote-show output, following the HEAD branch output. (Perhaps,\nprinting \"(not set)\" if the default isn't configured locally.)\n\n````\n$ git remote show origin | head\n* remote origin\n  Fetch URL: git@XXXX\n  Push  URL: git@XXXX\n  HEAD branch: develop\n  Local default branch: foo\n  Remote branches:\n```\n\nOr perhaps adding a line at the bottom with the other local refs. That\nwould allow additional notices when/if the local and remote defaults\ndiffer.\n\n>\n> What you _could_ do in your specific case, as you mention using\n> GitHub, is following their help page for \"setting the default\n> branch\"[2] for your GitHub repository (which you track locally as\n> \"origin\") to \"github-rename\".\n>\n> (in general, non-GitHub repository case, one could usually run there\n> either `git checkout github-rename`, if it`s not a bare repository,\n> or `git symbolic-ref HEAD refs/heads/github-rename`, if it`s a bare\n> repository)\n>\n> Afterwards, running `git remote show origin` inside your local\n> repository should output \"github-rename\" as HEAD value, as desired.\n>\n\nIn my case, the github configuration is correct, and the set-head\ncommand was only used to test the output of git-remote-show. The crux\nof my misunderstanding is that I thought git-remote-show should be\nreporting the contents of `refs/remotes/origin/HEAD`. Having that\ninformation reported somehow (preferably through git-remote-show)\nwould have clarified this for me.\n\n\n> p.s. To set your default remote branch locally to checked-out branch\n> on the remote end automatically, you can use `git remote set-head\n> origin --auto`, as documented[1]. It will inspect what`s inside\n> \"HEAD\" of the remote named \"origin\", and update your local\n> \"refs/remotes/origin/HEAD\" accordingly.\n>\n> [1] https://git-scm.com/docs/git-remote#git-remote-emset-headem\n> [2] https://help.github.com/articles/setting-the-default-branch/\n>\n> Regards,\n> Buga\n\nThanks for clarifying. Having this information surfaced a bit would be\na nice improvement, IMO.\n\nJason\n"},{"id":"326462","messageId":"20170815215947.hbddixjjwzlgsfuq@sigill.intra.peff.net","threadId":"46591","inReplyTo":"CAKNmmv3_rFNDDFVEeShAb3mEMOBL4z=oZXP8Df72D44stB_7BA@mail.gmail.com","subject":"Re: Bug: `git remote show <remote>` reports different HEAD branch than refs/remotes/<remote>/HEAD","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-08-15T21:59:47Z","receivedAt":"2017-08-15T21:59:53Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Aug 15, 2017 at 01:58:38PM -0400, Jason Karns wrote:\n\n> > On the other hand, what \"git remote show\" outputs for HEAD is a name\n> > of actually checked-out branch inside that remote repository - it`s\n> > what`s stored inside HEAD file of the remote repository root.\n> >\n> > So it is something set on the _remote_ end, you can`t influence it\n> > from your local repository.\n> \n> So _this_ is not what I expected. Thanks for clarifying.\n> \n> Considering that a fresh clone replicates the remote's default branch\n> as the local default for that remote, I wager (in the majority of\n> cases) that these two are the same. It would seem that what I would\n> like in this case is a feature change to git-remote-show to show both\n> the locally-configured and remote-configured defaults for the given\n> remote (similar in spirit to how git-remote-show already shows local\n> vs remote information: branches and their configurations for\n> push/pull).\n\nYes, I'd agree. This seems like exactly the kind of information that\n\"remote show\" was intended to display.\n\nIt should be a pretty straight-forward patch for anybody wanting to get\ntheir feet wet in git development. The trickier half of showing both is\ngetting the remote information, but we're already doing that. So I think\nany patch would want to:\n\n  1. Teach builtin/remote.c:show() to say \"Remote HEAD branch\" instead\n     of just \"HEAD branch\".\n\n  2. Add a \"Local HEAD branch\" that shows the local symref. That symref\n     is always refs/remotes/<remotename>/HEAD, which can be constructed\n     with a strbuf. And then resolve_refdup() can be used to get the\n     pointed-to ref (check the returned flags for REF_ISSYMREF, and\n     the string return value is the refname).\n\n-Peff\n"}]}