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

Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch

From
LSLeszek Swirski <leszeks@google.com>
Date
Mar 21, 2019, 15:43 UTC
Message-ID
<CAGRskv__Qe-F-grBtq5v-uhHE+BQAcAcOQtX-GKB+MNOrxs0hQ@mail.gmail.com>

Consider a repository with branch master, with upstream origin/master. If one is on master, and runs "git checkout @{u}" to get the upstream, then git branch stops working. The reason is that we end up on a detached HEAD, and git branch searches recent reflog entries to figure out where the HEAD was detached from (wt-status.c: wt_status_get_detached_from). Since @{u} is not a local branch, the checkout is inserted into the reflog as "moving from master to @{u}" rather than "moving from master to origin/master". This is because setup_branch_path (checkout.c) only updates the branch name for local branches, keeping the input name (here, "@{u}") otherwise. So, git branch sees "@{u}", decides that we are detached from "@{u}", tries to lookup "HEAD@{u}" and fails with "fatal: HEAD does not point to a branch"

I assume that either the reflog entry should be amended to print something more informative (moving from master to origin/master, or at least master@{u}, or the SHA...), or the reflog search in wt_status_get_detached_from should do something cleverer with relative refs.

- Leszek
Next: Junio C Hamano
Message 1 of 2 in “Bug: git checkout @{u} breaks git branch if the upstream isn't a local branch”
  1. Leszek SwirskiMar 21, 2019
  2. Junio C HamanoMar 22, 2019

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.