Re: [PATCH] checkout: add --fetch to fetch remote before resolving start-point
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Apr 24, 2026, 17:12 UTC
- Message-ID
- <CALnO6CCNoo8y2V5KmE0KQ6qDurZELipFowcr=ZpZ3ocVB-uLjA@mail.gmail.com>
- In-Reply-To
- <pull.2281.git.git.1777024991531.gitgitgadget@gmail.com>
On Fri, Apr 24, 2026 at 6:08 AM Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 23 quoted lines
> > From: Harald Nordgren <haraldnordgren@gmail.com> > > Add a --fetch option to git checkout and git switch, plus a > checkout.autoFetch config to enable it by default. When set and the > start-point argument names a configured remote (either bare, like > "origin", or prefixed, like "origin/foo"), fetch that remote before > resolving the ref. Aborts the checkout if the fetch fails. > > Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> > --- > checkout: add --fetch to fetch remote before resolving start-point > > A workflow I run several times a day looks like: > > git fetch origin > git checkout -b new_branch origin/some-branch > > > The first command exists purely to make the second one see an up-to-date > view of the remote. If I forget it, origin/some-branch points at a stale > commit, and I end up creating a local branch from the wrong starting > point.
When you realize this, "git pull --rebase" should help correct it.
Show 14 quoted lines
> > This series teaches git checkout (and git switch) a new --fetch flag > that folds the two steps into one: > > git checkout --fetch -b new_branch origin/some-branch > > > When the start-point argument names a configured remote — either bare > (origin, which resolves to the remote's default branch) or in / form — > git fetch is run before the start-point is resolved. If the fetch fails, > the checkout aborts and no local branch is created. > > A new checkout.autoFetch config option enables the same behavior by > default, for users who always want it.
I could certainly see this being convenient. (I don't have any comment on the code at this time.)