Re: [PATCH] remote: add --set-head option to 'git remote add'
Show 25 quoted lines
> Le 25 avr. 2026 à 07:19, Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com> a écrit :
>
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Mirror the behavior 'git clone' applies to its first remote: after
> fetching, set refs/remotes/<name>/HEAD to the remote's default branch.
>
> Equivalent to running:
>
> git remote add -f <name> <url>
> git remote set-head <name> -a
>
> The new option implies --fetch.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
> remote: add --set-head option to 'git remote add'
>
> When using GitHub's gh tool to fork a repo, it seems that set-head isn't
> run on the upstream remote. So its default branch is not recorded
> locally, meaning that 'git log fork' will not work.
>
> With git remote add --set-head upstream , the default branch is set in
> the same step and things can work out of the box after a small change on
> 'gh' that I will do as a next step.
I’m not totally opposed to this convenience, but couldn’t we also just teach gh to run set-head as a second command?
(Of course, it will need a version check; if memory serves not all Git versions used in practice have this command? But I am on mobile and have not validated the history of git-remote’s sub-commands.)