{"thread":{"id":"66553","subject":"[PATCH] branch: let inherit track a remote-tracking start point","startedAt":"2026-10-16T07:02:45Z","lastAt":"2026-10-19T20:06:10Z","messageCount":8,"participants":["Harald Nordgren via GitGitGadget","Junio C Hamano","Harald Nordgren","Phillip Wood","Ben Knoble"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555215","messageId":"pull.2450.git.git.1792134165785.gitgitgadget@gmail.com","threadId":"66553","inReplyTo":null,"subject":"[PATCH] branch: let inherit track a remote-tracking start point","fromName":"Harald Nordgren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-16T07:02:45Z","receivedAt":"2026-10-16T07:02:45Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"From: Harald Nordgren <haraldnordgren@gmail.com>\n\nWith branch.autoSetupMerge=inherit, \"git switch topic\" creates a local\ntopic branch from origin/topic with no upstream, and warns that no\nremote is set. \"git switch -c topic origin/topic\" and an explicit\n\"--track=inherit\" do the same.\n\nA remote-tracking branch has no upstream of its own to copy. Make\ninherit use it as the upstream directly, as the default \"true\" does,\nso that inherit sets up tracking in every case the default does.\n\nSigned-off-by: Harald Nordgren <haraldnordgren@gmail.com>\n---\n    branch: let inherit track a remote-tracking start point\n    \n    With branch.autoSetupMerge=inherit, make git switch -c new_branch\n    upstream/master work without a warning, and sets the remote branch\n    upstream/master as the upstream.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2450%2FHaraldNordgren%2Fhn%2Fbranch-inherit-remote-tracking-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2450/HaraldNordgren/hn/branch-inherit-remote-tracking-v1\nPull-Request: https://github.com/git/git/pull/2450\n\n Documentation/config/branch.adoc |  2 +-\n Documentation/git-branch.adoc    |  4 +++-\n branch.c                         |  3 +++\n t/t2060-switch.sh                | 17 +++++++++++++++++\n 4 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc\nindex c2acd89c99..6d9fbe5353 100644\n--- a/Documentation/config/branch.adoc\n+++ b/Documentation/config/branch.adoc\n@@ -10,7 +10,7 @@\n `always`;; automatic setup is done when the starting point is either a\n \tlocal branch or remote-tracking branch\n `inherit`;; if the starting point has a tracking configuration, it is copied to the new\n-\tbranch\n+\tbranch. A remote-tracking starting point is tracked directly, as with `true`.\n `simple`;; automatic setup is done only when the starting point\n \tis a remote-tracking branch and the new branch has the same name as the\n \tremote branch.\ndiff --git a/Documentation/git-branch.adoc b/Documentation/git-branch.adoc\nindex bfdf459329..238d99fd27 100644\n--- a/Documentation/git-branch.adoc\n+++ b/Documentation/git-branch.adoc\n@@ -280,7 +280,9 @@ remove it anyway.\n The exact upstream branch is chosen depending on the optional argument:\n `-t`, `--track`, or `--track=direct` means to use the start-point branch\n itself as the upstream; `--track=inherit` means to copy the upstream\n-configuration of the start-point branch.\n+configuration of the start-point branch. A remote-tracking start-point\n+has no upstream of its own, so `--track=inherit` uses it as the upstream\n+directly.\n +\n The `branch.autoSetupMerge` configuration variable specifies how `git switch`,\n `git checkout` and `git branch` should behave when neither `--track` nor\ndiff --git a/branch.c b/branch.c\nindex 22f4f46b96..2c23179775 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -263,6 +263,9 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,\n \tif (!track)\n \t\tBUG(\"asked to set up tracking, but tracking is disallowed\");\n \n+\tif (track == BRANCH_TRACK_INHERIT && !starts_with(orig_ref, \"refs/heads/\"))\n+\t\ttrack = BRANCH_TRACK_REMOTE;\n+\n \tmemset(&tracking, 0, sizeof(tracking));\n \ttracking.spec.dst = (char *)orig_ref;\n \ttracking.srcs = &tracking_srcs;\ndiff --git a/t/t2060-switch.sh b/t/t2060-switch.sh\nindex cec2fe6876..da9d01ab84 100755\n--- a/t/t2060-switch.sh\n+++ b/t/t2060-switch.sh\n@@ -146,6 +146,23 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' '\n \ttest_cmp_config \"\" --default \"\" branch.main2.merge\n '\n \n+test_expect_success 'autoSetupMerge=inherit tracks a remote-tracking start point' '\n+\tgit clone . downstream &&\n+\t(\n+\t\tcd downstream &&\n+\t\tgit config branch.autoSetupMerge inherit &&\n+\t\tgit switch -c new_branch origin/main &&\n+\t\tgit status >../actual &&\n+\t\tcat >expect <<-EOF &&\n+\t\tOn branch new_branch\n+\t\tYour branch is up to date with ${SQ}origin/main${SQ}.\n+\n+\t\tnothing to commit, working tree clean\n+\t\tEOF\n+\t\ttest_cmp expect ../actual\n+\t)\n+'\n+\n test_expect_success 'switch back when temporarily detached and checked out elsewhere ' '\n \ttest_when_finished \"\n \t\tgit worktree remove wt1 ||:\n\nbase-commit: f57c9a73884400380bddd172acc88b569834f909\n-- \ngitgitgadget\n\n"},{"id":"555250","messageId":"xmqqcxt9h9g6.fsf@gitster.g","threadId":"66553","inReplyTo":"pull.2450.git.git.1792134165785.gitgitgadget@gmail.com","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-16T16:55:05Z","receivedAt":"2026-10-16T16:55:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Harald Nordgren via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  `inherit`;; if the starting point has a tracking configuration, it is copied to the new\n> -\tbranch\n> +\tbranch. A remote-tracking starting point is tracked directly, as with `true`.\n\nThat is \"A remote-tracking branch given as a starting point\", not \"A\nremote-tracking starting point\".  Don't abbreviate and drop \"branch\".\n\nIf a starting point is not a remote-tracking branch, shouldn't the\nsame thing happen, by the way?  IOW, shouldn't the updated text and\nbehaviour be more like\n\n\t`inherit`;; if the starting point has a tracking\n\tconfiguration, it is copied to the new branch.  Otherwise,\n\tthe new branch is set to track the starting point itself.\n\nI am not sure if it is the users of `inherit` want that forking a\nnew branch from something that they know is *not* tracking anything\nsuddenly starts to track the starting point (whether it is a\nremote-tracking branch or something else).\n\nLooking at the originating commit d3115660b4 (branch: add flags and\nconfig to inherit tracking, 2021-12-20), it only talks about what\nthey want to do when the starting point does track something, and\nforgets to say what they want when it does not track anything (the\nauthor CC'ed in case he retains the memory of the motivation from 5\nyears ago), but if you ask me _now_, not doing anything, i.e., the\nbehaviour the old commit happened to have implemented without\nexplanation does sound like the right thing to do.\n\nWhat we should do if this change of behaviour turns out to be\nundesirable?\n\nPerhaps `inherit` should gain a synonym `inherit-or-ignore` for\nthose who prefer the current behaviour, and we want two extra\nbehaviours, `inherit-or-fail` that complains and dies if the\nspecified starting point does not have anything for the new branch\nto inherit, and `inherit-or-direct` that uses the fallback\ndefinition, or something?\n\n"},{"id":"555309","messageId":"CAHwyqnVwnMi+DzQDvS6mgUzg-CWACUviVkYv-UiYJT+Yq83QLg@mail.gmail.com","threadId":"66553","inReplyTo":"xmqqcxt9h9g6.fsf@gitster.g","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-17T09:54:15Z","receivedAt":"2026-10-17T09:54:15Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"On Fri, Oct 16, 2026 at 6:55 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Harald Nordgren via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n> >  `inherit`;; if the starting point has a tracking configuration, it is copied to the new\n> > -     branch\n> > +     branch. A remote-tracking starting point is tracked directly, as with `true`.\n>\n> That is \"A remote-tracking branch given as a starting point\", not \"A\n> remote-tracking starting point\".  Don't abbreviate and drop \"branch\".\n\nThanks!\n\n> I am not sure if it is the users of `inherit` want that forking a\n> new branch from something that they know is *not* tracking anything\n> suddenly starts to track the starting point (whether it is a\n> remote-tracking branch or something else).\n\nFor me it's simple, only tracking when the starting point is a remote branch.\n\n> Looking at the originating commit d3115660b4 (branch: add flags and\n> config to inherit tracking, 2021-12-20), it only talks about what\n> they want to do when the starting point does track something, and\n> forgets to say what they want when it does not track anything (the\n> author CC'ed in case he retains the memory of the motivation from 5\n> years ago), but if you ask me _now_, not doing anything, i.e., the\n> behaviour the old commit happened to have implemented without\n> explanation does sound like the right thing to do.\n>\n> What we should do if this change of behaviour turns out to be\n> undesirable?\n>\n> Perhaps `inherit` should gain a synonym `inherit-or-ignore` for\n> those who prefer the current behaviour, and we want two extra\n> behaviours, `inherit-or-fail` that complains and dies if the\n> specified starting point does not have anything for the new branch\n> to inherit, and `inherit-or-direct` that uses the fallback\n> definition, or something?\n\nSeems quite overkill for the relatively small problem this is solving.\nBut it would be interesting to hear the original author's POV.\n\n\nHarald\n\n"},{"id":"555344","messageId":"d2264240-1530-48a2-ac3e-ae46f855872f@gmail.com","threadId":"66553","inReplyTo":"xmqqcxt9h9g6.fsf@gitster.g","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-18T09:59:57Z","receivedAt":"2026-10-18T09:59:57Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 16/10/2026 17:55, Junio C Hamano wrote:\n> \"Harald Nordgren via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> >>   `inherit`;; if the starting point has a tracking configuration, it is copied to the new\n>> -\tbranch\n>> +\tbranch. A remote-tracking starting point is tracked directly, as with `true`.\n> > That is \"A remote-tracking branch given as a starting point\", not \"A\n> remote-tracking starting point\".  Don't abbreviate and drop \"branch\".\n> > If a starting point is not a remote-tracking branch, shouldn't the\n> same thing happen, by the way?  IOW, shouldn't the updated text and\n> behaviour be more like\n> > \t`inherit`;; if the starting point has a tracking\n> \tconfiguration, it is copied to the new branch.  Otherwise,\n> \tthe new branch is set to track the starting point itself.\n> > I am not sure if it is the users of `inherit` want that forking a\n> new branch from something that they know is *not* tracking anything\n> suddenly starts to track the starting point (whether it is a\n> remote-tracking branch or something else).\n\nFor me it depends on what I'm forking from. If I create a branch on my desktop, push it to my server and then create a local branch from that on my laptop, I normally want the new branch to track something like origin/master rather than the starting point. However, if I create a new branch from origin/master then I do want to track the starting point. So it is not clear to me that the behavior proposed here is better than the current behavior, but equally I don't think it is any worse. Having some way of saying \"set up tracking when the starting point matches one of these patterns\" might be useful, but I find the tracking options to \"git switch -c\" so confusing I normally just run \"git branch --set-upstream-to\" afterwards to set the upstream I want.\n\nThanks\n\nPhillip\n\n\n> Looking at the originating commit d3115660b4 (branch: add flags and\n> config to inherit tracking, 2021-12-20), it only talks about what\n> they want to do when the starting point does track something, and\n> forgets to say what they want when it does not track anything (the\n> author CC'ed in case he retains the memory of the motivation from 5\n> years ago), but if you ask me _now_, not doing anything, i.e., the\n> behaviour the old commit happened to have implemented without\n> explanation does sound like the right thing to do.\n> > What we should do if this change of behaviour turns out to be\n> undesirable?\n> > Perhaps `inherit` should gain a synonym `inherit-or-ignore` for\n> those who prefer the current behaviour, and we want two extra\n> behaviours, `inherit-or-fail` that complains and dies if the\n> specified starting point does not have anything for the new branch\n> to inherit, and `inherit-or-direct` that uses the fallback\n> definition, or something?\n\n\n"},{"id":"555352","messageId":"CAHwyqnV=iiocV2FA32-X8LTgYwWmzQguPtkykFKM-t7B7ttNOw@mail.gmail.com","threadId":"66553","inReplyTo":"d2264240-1530-48a2-ac3e-ae46f855872f@gmail.com","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Harald Nordgren","fromEmail":"haraldnordgren@gmail.com","sentAt":"2026-10-18T15:19:46Z","receivedAt":"2026-10-18T15:19:46Z","isPatch":true,"sender":{"key":"haraldnordgren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9569897?v=4"},"body":"> For me it depends on what I'm forking from. If I create a branch on my\n> desktop, push it to my server and then create a local branch from that\n> on my laptop, I normally want the new branch to track something like\n> origin/master rather than the starting point. However, if I create a new\n> branch from origin/master then I do want to track the starting point. So\n> it is not clear to me that the behavior proposed here is better than the\n> current behavior, but equally I don't think it is any worse. Having some\n> way of saying \"set up tracking when the starting point matches one of\n> these patterns\" might be useful, but I find the tracking options to \"git\n> switch -c\" so confusing I normally just run \"git branch\n> --set-upstream-to\" afterwards to set the upstream I want.\n\nI don't actually use 'git switch -c', I just used that in the example\nbecause it's the *modern* way to do things. In reality I always run\n'git checkout -b'. I agree about `set-upstream-to`, there is probably\nno single terminal command that I run more than\n\n    git branch --set-upstream-to=origin\n\nYour example got me thinking. Maybe we should go the other way? If we\ncan inherit from the branch we are coming from, should we do that as\nfirst prio? Because of the `--set-upstream-to=origin` usage, we will\nlikely already be tracking the right one. So\n\n    git checkout -b first_branch\n    git branch --set-upstream-to=origin/master\n    git checkout -b new_branch origin/another_branch\n\ncould give us a 'new_branch' that tracks what 'first_branch' tracked,\ni.e. 'origin/master'. Maybe as a fallback, we could have the new\nbehavior from my v1, so if 'first_branch' has no tracking branch, then\n\n    git checkout -b first_branch\n    git checkout -b new_branch origin/another_branch\n\nfalls back to 'new_branch ' tracking 'origin/another_branch' instead?\nOr not, maybe this fallback is just bad?\n\n\nHarald\n\n"},{"id":"555419","messageId":"BCD8B077-5A67-4A56-9DEB-9B482D580226@gmail.com","threadId":"66553","inReplyTo":"CAHwyqnVwnMi+DzQDvS6mgUzg-CWACUviVkYv-UiYJT+Yq83QLg@mail.gmail.com","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-19T14:25:15Z","receivedAt":"2026-10-19T14:25:15Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 17 oct. 2026 à 05:55, Harald Nordgren <haraldnordgren@gmail.com> a écrit :\n> \n> ﻿On Fri, Oct 16, 2026 at 6:55 PM Junio C Hamano <gitster@pobox.com> wrote:\n>> Looking at the originating commit d3115660b4 (branch: add flags and\n>> config to inherit tracking, 2021-12-20), it only talks about what\n>> they want to do when the starting point does track something, and\n>> forgets to say what they want when it does not track anything (the\n>> author CC'ed in case he retains the memory of the motivation from 5\n>> years ago), but if you ask me _now_, not doing anything, i.e., the\n>> behaviour the old commit happened to have implemented without\n>> explanation does sound like the right thing to do.\n>> What we should do if this change of behaviour turns out to be\n>> undesirable?\n>> Perhaps `inherit` should gain a synonym `inherit-or-ignore` for\n>> those who prefer the current behaviour, and we want two extra\n>> behaviours, `inherit-or-fail` that complains and dies if the\n>> specified starting point does not have anything for the new branch\n>> to inherit, and `inherit-or-direct` that uses the fallback\n>> definition, or something?\n> \n> Seems quite overkill for the relatively small problem this is solving.\n> But it would be interesting to hear the original author's POV.\n\nOverkill, possibly, but easier to expand in a compatible way over time\n(other than piling new modifier --options on top, which makes the CLI confusing IMO).\n"},{"id":"555420","messageId":"65ACF5B8-875F-40CB-A361-14452A38F405@gmail.com","threadId":"66553","inReplyTo":"CAHwyqnV=iiocV2FA32-X8LTgYwWmzQguPtkykFKM-t7B7ttNOw@mail.gmail.com","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-10-19T14:26:38Z","receivedAt":"2026-10-19T14:26:38Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 18 oct. 2026 à 11:20, Harald Nordgren <haraldnordgren@gmail.com> a écrit :\n> \n> ﻿\n>> \n>> For me it depends on what I'm forking from. If I create a branch on my\n>> desktop, push it to my server and then create a local branch from that\n>> on my laptop, I normally want the new branch to track something like\n>> origin/master rather than the starting point. However, if I create a new\n>> branch from origin/master then I do want to track the starting point. So\n>> it is not clear to me that the behavior proposed here is better than the\n>> current behavior, but equally I don't think it is any worse. Having some\n>> way of saying \"set up tracking when the starting point matches one of\n>> these patterns\" might be useful, but I find the tracking options to \"git\n>> switch -c\" so confusing I normally just run \"git branch\n>> --set-upstream-to\" afterwards to set the upstream I want.\n> \n> I don't actually use 'git switch -c', I just used that in the example\n> because it's the *modern* way to do things. In reality I always run\n> 'git checkout -b'. I agree about `set-upstream-to`, there is probably\n> no single terminal command that I run more than\n> \n>    git branch --set-upstream-to=origin\n\nCurious. I typically do\n\n    git switch -c topic origin\n\nand am happy. (When creating a branch that *doesn’t* start\nat origin but still should track it, I use « branch -u » as shown, too.)\n"},{"id":"555456","messageId":"xmqqqzhl4frh.fsf@gitster.g","threadId":"66553","inReplyTo":"BCD8B077-5A67-4A56-9DEB-9B482D580226@gmail.com","subject":"Re: [PATCH] branch: let inherit track a remote-tracking start point","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-19T20:06:10Z","receivedAt":"2026-10-19T20:06:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ben Knoble <ben.knoble@gmail.com> writes:\n\n> Overkill, possibly, but easier to expand in a compatible way over time\n> (other than piling new modifier --options on top, which makes the CLI confusing IMO).\n\nYes, exactly.  A myopic initial design can easily paint us into\na UI corner from which we cannot easily escape without awkward\noptions.  That is why I care.\n\nThanks.\n\n"}]}