git/list[1] front-page[2] threads[3] people[4] search[5] about
 

feature request: set remote/HEAD with fetch

From
Bence Ferdinandy <bence@ferdinandy.com>
Date
Aug 16, 2024, 11:53 UTC
Message-ID
<D3HBD7C1FR14.74FL1Q1S9UCB@ferdinandy.com>
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

Next: brian m. carlson
Message 1 of 7 in “feature request: set remote/HEAD with fetch”
  1. Bence FerdinandyAug 16, 2024
  2. brian m. carlsonAug 16, 2024
  3. Junio C HamanoAug 16, 2024
  4. Jeff KingAug 17, 2024
  5. Bence FerdinandyAug 17, 2024
  6. Johannes SchindelinAug 19, 2024
  7. Bence FerdinandyAug 20, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.