Skip to content

branch: let inherit track a remote-tracking start point - #2450

Open
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:hn/branch-inherit-remote-tracking
Open

HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:hn/branch-inherit-remote-tracking

Conversation

@HaraldNordgren

@HaraldNordgren HaraldNordgren commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

With branch.autoSetupMerge=inherit, make git switch -c new_branch upstream/master work without a warning, and sets the remote branch upstream/master as the upstream.

@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2450.git.git.1792134165785.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2450/HaraldNordgren/hn/branch-inherit-remote-tracking-v1

To fetch this version to local tag pr-git-2450/HaraldNordgren/hn/branch-inherit-remote-tracking-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2450/HaraldNordgren/hn/branch-inherit-remote-tracking-v1

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  `inherit`;; if the starting point has a tracking configuration, it is copied to the new
> -	branch
> +	branch. A remote-tracking starting point is tracked directly, as with `true`.

That is "A remote-tracking branch given as a starting point", not "A
remote-tracking starting point".  Don't abbreviate and drop "branch".

If a starting point is not a remote-tracking branch, shouldn't the
same thing happen, by the way?  IOW, shouldn't the updated text and
behaviour be more like

	`inherit`;; if the starting point has a tracking
	configuration, it is copied to the new branch.  Otherwise,
	the new branch is set to track the starting point itself.

I am not sure if it is the users of `inherit` want that forking a
new branch from something that they know is *not* tracking anything
suddenly starts to track the starting point (whether it is a
remote-tracking branch or something else).

Looking at the originating commit d3115660b4 (branch: add flags and
config to inherit tracking, 2021-12-20), it only talks about what
they want to do when the starting point does track something, and
forgets to say what they want when it does not track anything (the
author CC'ed in case he retains the memory of the motivation from 5
years ago), but if you ask me _now_, not doing anything, i.e., the
behaviour the old commit happened to have implemented without
explanation does sound like the right thing to do.

What we should do if this change of behaviour turns out to be
undesirable?

Perhaps `inherit` should gain a synonym `inherit-or-ignore` for
those who prefer the current behaviour, and we want two extra
behaviours, `inherit-or-fail` that complains and dies if the
specified starting point does not have anything for the new branch
to inherit, and `inherit-or-direct` that uses the fallback
definition, or something?

With branch.autoSetupMerge=inherit, "git switch topic" creates a local
topic branch from origin/topic with no upstream, and warns that no
remote is set. "git switch -c topic origin/topic" and an explicit
"--track=inherit" do the same.

A remote-tracking branch has no upstream of its own to copy. Make
inherit use it as the upstream directly, as the default "true" does,
so that inherit sets up tracking in every case the default does.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
@HaraldNordgren
HaraldNordgren force-pushed the hn/branch-inherit-remote-tracking branch from 32969fc to c39c2f2 Compare October 17, 2026 09:51
@gitgitgadget-git

Copy link
Copy Markdown

Harald Nordgren wrote on the Git mailing list (how to reply to this email):

On Fri, Oct 16, 2026 at 6:55 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >  `inherit`;; if the starting point has a tracking configuration, it is copied to the new
> > -     branch
> > +     branch. A remote-tracking starting point is tracked directly, as with `true`.
>
> That is "A remote-tracking branch given as a starting point", not "A
> remote-tracking starting point".  Don't abbreviate and drop "branch".

Thanks!

> I am not sure if it is the users of `inherit` want that forking a
> new branch from something that they know is *not* tracking anything
> suddenly starts to track the starting point (whether it is a
> remote-tracking branch or something else).

For me it's simple, only tracking when the starting point is a remote branch.

> Looking at the originating commit d3115660b4 (branch: add flags and
> config to inherit tracking, 2021-12-20), it only talks about what
> they want to do when the starting point does track something, and
> forgets to say what they want when it does not track anything (the
> author CC'ed in case he retains the memory of the motivation from 5
> years ago), but if you ask me _now_, not doing anything, i.e., the
> behaviour the old commit happened to have implemented without
> explanation does sound like the right thing to do.
>
> What we should do if this change of behaviour turns out to be
> undesirable?
>
> Perhaps `inherit` should gain a synonym `inherit-or-ignore` for
> those who prefer the current behaviour, and we want two extra
> behaviours, `inherit-or-fail` that complains and dies if the
> specified starting point does not have anything for the new branch
> to inherit, and `inherit-or-direct` that uses the fallback
> definition, or something?

Seems quite overkill for the relatively small problem this is solving.
But it would be interesting to hear the original author's POV.


Harald

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant