]> git.ipfire.org Git - thirdparty/git.git/commit
checkout: extend --track with a "fetch" mode to refresh start-point
authorHarald Nordgren <haraldnordgren@gmail.com>
Sat, 23 May 2026 19:48:34 +0000 (19:48 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 24 May 2026 08:36:12 +0000 (17:36 +0900)
commit0233259d86bd9d49fe3d061871fdb3b27f5cd98a
treeb3ae6706477f95ffdb6e20bf24913f441a506f33
parentae051d96118a684bdee3548fb58c2cb33a2fa8d9
checkout: extend --track with a "fetch" mode to refresh start-point

Add a "fetch" mode to the "--track" option of "git checkout" / "git
switch" that refreshes <start-point> before checking it out:

    git checkout -b new_branch --track=fetch origin/some-branch

is shorthand for

    git fetch origin some-branch
    git checkout -b new_branch --track origin/some-branch

Identify the remote whose configured fetch refspec maps to
<start-point> using find_tracking_remote_for_ref() (the same lookup
"--track" uses to pick which remote to record in
branch.<name>.remote), then run "git fetch <remote> <src-ref>" for
just that ref so other remote-tracking branches are left untouched.
When <start-point> is a bare <remote> (e.g. "origin"), follow
refs/remotes/<remote>/HEAD to learn which branch to refresh. If
"git fetch" fails but the remote-tracking ref already exists locally,
warn and proceed from the existing tip; otherwise abort.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-checkout.adoc
Documentation/git-switch.adoc
builtin/checkout.c
t/t7201-co.sh