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

Head, Branch != Head -> Branch?

From
TZTomas Zubiri <me@tomaszubiri.com>
Date
Dec 14, 2019, 18:00 UTC
Message-ID
<CAE3VKEpPye+GyR7Uo9WBa=1i1L=dFq9AHfdNnhiw19K-jWLtBA@mail.gmail.com>

Hello, I'm writing because I believe I found a case where git could be simplified. I'm posting my terminal log so that you can see exactly what I saw. Comments are marked with >> . Important spanish git was translated.

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git status
HEAD detached at 54da1ac
Cambios no rastreados para el commit:
  (usa "git add <archivo>..." para actualizar lo que será confirmado)
  (usa "git checkout -- <archivo>..." para descartar los cambios en el
directorio de trabajo)

modificado: cv/en/index.html modificado: cv/index.html

sin cambios agregados al commit (usa "git add" y/o "git commit -a")
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git add cv/en/index.html
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git add cv/index.html
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git commit -m
"Agrego mi celular, por favor no me manden spam"
[HEAD detached 82b2b55] Agrego mi celular, por favor no me manden spam
 2 files changed, 3 insertions(+), 1 deletion(-)
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push
fatal: Actualmente no estás en una rama.
Para hacer un push a la historia que lleva al estado actual
(HEAD detached), use
git push origin HEAD:<nombre-de-rama-remota>
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push origin ^C
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 82b2b55b3f7768a60e3d8bcda97d4d623ff0e044 (HEAD)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
>> This is the commit I wanted to push
commit 54da1ac07a5c7c2e7234911a0af76aee042b5b99
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 20:33:11 2019 -0300
    Limpio url para cv en inglés.
>> This is an abandoned commit I didn't push.
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo
>> This is what's in production
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git checkout origin/master^C
>> ^C cancels the command, I notice there's an extra commit.

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git branch newmaster (base) tomas@toms:~/Projects/tomaszubiri.com/site$ git checkout origin/master La posición previa de HEAD era 82b2b55 Agrego mi celular, por favor no me manden spam

>> Previous head position was..
HEAD está ahora en 81542e7 especifico tecnologías de contribución de codigo
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git cherry-pick newmaster
[HEAD desacoplado 912c91a] Agrego mi celular, por favor no me manden spam
 Date: Fri Dec 13 21:37:30 2019 -0300
 2 files changed, 3 insertions(+), 1 deletion(-)
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 912c91a92e17de33247e2040d1dd01adbfc218eb (HEAD)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo
>> Looks good.

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git branch master fatal: Una rama llamada 'master' ya existe. (base) tomas@toms:~/Projects/tomaszubiri.com/site$ git branch -D master Eliminada la rama master (era 679eaf3).. (base) tomas@toms:~/Projects/tomaszubiri.com/site$ git branch master (base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push^C

>> Gotta double check.
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 912c91a92e17de33247e2040d1dd01adbfc218eb (HEAD, master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push fatal: Actualmente no estás en una rama.

>> Fatal: You are not currently on a branch.

Para hacer un push a la historia que lleva al estado actual (HEAD desacoplado), use

git push origin HEAD:<nombre-de-rama-remota>

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push origin/master fatal: Actualmente no estás en una rama. Para hacer un push a la historia que lleva al estado actual (HEAD desacoplado), use

git push origin/master HEAD:<nombre-de-rama-remota>
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push ^Cigin/master
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 912c91a92e17de33247e2040d1dd01adbfc218eb (HEAD, master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push >> So confused I repeated a command. fatal: Actualmente no estás en una rama. Para hacer un push a la historia que lleva al estado actual (HEAD desacoplado), use

git push origin HEAD:<nombre-de-rama-remota>
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 912c91a92e17de33247e2040d1dd01adbfc218eb (HEAD, master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push fatal: Actualmente no estás en una rama.

>> Fatal: Not currently on a branch

Para hacer un push a la historia que lleva al estado actual (HEAD desacoplado), use

git push origin HEAD:<nombre-de-rama-remota>

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git checkout master Cambiado a rama 'master'

>> Now on 'master' branch

(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git push fatal: La rama actual master no tiene una rama upstream.

>> This error message is something I would expect, since I deleted the master branch and created a new one. That's ok.

Para realizar un push de la rama actual y configurar el remoto como upstream, use

git push --set-upstream origin master
(base) tomas@toms:~/Projects/tomaszubiri.com/site$ git log
commit 912c91a92e17de33247e2040d1dd01adbfc218eb (HEAD -> master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Dec 13 21:37:30 2019 -0300
    Agrego mi celular, por favor no me manden spam
commit 81542e725149ba5da36560ad14d4871eb7ea01e6 (origin/master)
Author: Tomas Zubiri <me@tomaszubiri.com>
Date:   Fri Oct 18 17:08:50 2019 -0300
    especifico tecnologías de contribución de codigo

Thank you for stepping in my shoes for a moment here. I understand now that Head is a special kind of tag and it must be attached to a branch. But I don't yet understand why the distinction between head attached to branch and head and branch in the same commit is necessary. Couple that to the fact that git forgot (perhaps with good cause) what remote master pointed to, it feels like this is a place where git could improve in simplicity.

My naive suggestion would be as follows:
 When HEAD is pointing to a commit and another branch is pointing to
the same commit, consider the head attached to that commit.
I understand that, if there were multiple branches on the same commit,
git wouldn't know what remote to push to, so in such case a
disambiguation would be needed, but the case here would be that we are
on 2 branches, not none!
What am I missing here? Would this change have catastrophic consequences?
Regards.
Next: Tomas Zubiri
Message 1 of 5 in “Head, Branch != Head -> Branch?”
  1. Tomas ZubiriDec 14, 2019
  2. Tomas ZubiriDec 14, 2019
  3. mattr94@gmail.comDec 14, 2019
  4. Tomas ZubiriDec 15, 2019
  5. Joshua TevesDec 15, 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.