git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* feature request: set remote/HEAD with fetch
@ 2024-08-16 11:53 Bence Ferdinandy
  2024-08-16 21:55 ` brian m. carlson
  0 siblings, 1 reply; 7+ messages in thread
From: Bence Ferdinandy @ 2024-08-16 11:53 UTC (permalink / raw)
  To: git

Hi,

this comes after a bit of discussion on #git. The current behaviour of git is
that when cloning, `refs/remotes/[remote]/HEAD` is set, but if you use `git
init` and `git remote add`, then you must manually run `git remote set-head -a`
to arrive at the same state. Having origin/HEAD set is pretty useful for
scripting and aliases, because you don't need to remember what the current
project uses (origin/[master|main|trunk|etc]).

I would propose that running `git fetch` should also update remote/HEAD. In
case there is a possibility that it is useful in some cases that remote/HEAD is
actually different from whatever is set in the remote repository as the default
branch, I think a setting for opt-out would be better, and the default
behaviour should be essentially always running `set-head -a`.

My current workaround is an alias:
    fetchall = !git fetch --all && git remote | xargs -i git remote set-head -a {}

which works for me, but I think it would be more elegant not to have to do this.

A slight aside: if `refs/remotes/[remote]/HEAD` is set you still might have
a problem of easily accessing the current remote's HEAD, since @{upstream} will
point to the branch. It's again not something you can't script around, but
would be cool if there were an easy way of avoiding hardcoded "origin" in
aliases and scripts.

Thanks for considering!

Best,
Bence

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-08-20 21:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 11:53 feature request: set remote/HEAD with fetch Bence Ferdinandy
2024-08-16 21:55 ` brian m. carlson
2024-08-16 22:10   ` Junio C Hamano
2024-08-17  5:02   ` Jeff King
2024-08-17 19:00     ` Bence Ferdinandy
2024-08-19 16:40       ` Johannes Schindelin
2024-08-20 21:38         ` Bence Ferdinandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).