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

Re: What actually is a branch?

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jul 8, 2021, 03:39 UTC
Message-ID
<60e67389a4adc_306ac1208fd@natae.notmuch>
In-Reply-To
<c740a4f0-011f-762e-4f49-f85d1b3abc99@mfriebe.de>
Martin wrote:
Show 21 quoted lines
> On 08/07/2021 00:07, Sergey Organov wrote:
> > Felipe Contreras <felipe.contreras@gmail.com> writes:
> >>
> >> This is works if your base (or tail, or whatever) is static, but many
> >> branches jump around, and that's where @{tail} comes in handy.
> > 
> > Yeah, I see. When I need to make a branch jump around, I do need to
> > manually move my references, but that's fortunately very rare use-case
> > for me. Having direct support for that is still a win.
> > 
> >>
> >> You can do this:
> >>
> >>    git rebase --onto foo@{upstream} foo@{tail}
> >>
> >> This will always rebase the right commits (no need to look into the
> >> reflog). So you can say that the branch is foo@{tail}..foo.
> > 
> 
> Maybe I am missing something, is tail for tracking branches only, or for 
> just any branch?
Any branch.
Show 9 quoted lines
> If for any branch, looking at
> 
>    A => B => C => D  master
>         |
>          \          / => G => H  branch_1
>           => E => F
>                     \ => I => J  branch_2
> 
> Where is the base of branch_1 and branch_2?

It depends where the corresponding `git switch --create` command was issued.

If you did `git switch --create branch_1 B`, then @{tail} is B. If you did `git switch --create branch_1 F`, then @{tail} is F.

> (and does it matter if they have an upstream)
No. That's completely independent.
Show 7 quoted lines
> Maybe branch_1 diverged from Master, and then branch_2 from branch_1?
> 
> Maybe the other way round.
> 
> Maybe there was a branch_0 (that got removed),
> and branch_0 diverged from master, and branch_1 and branch_2 both from 
> branch_0?
Yeap, the tails of branch_1 and branch_2 could be literally anywhere.

That information is not recoverable from the current data structures of git, thus the proposal to add a new one.

Show 5 quoted lines
> ---
> Also base may be misleading.
> 
> If head is the one end of the commit chains, then base should be the other.
> But all branches contain commits A (and B). So the base would be A.

All branches contain A, but only one branch could have A as a base/tail (under normal operations), and likely none do.

Suppose branch_2 was created this way:
  git switch --create branch_2 A

Then commit B was created under branch_2. Then master was fast-forwarded to branch_2, so you have:

                 A => B master
                 ^    ^
  tail/branch_2 -+    +- head/branch_2
Both branches have A, but only branch_2 has A as tail.

As both branches move forward they diverge, and the "fork-point" is B, but B is not the tail of *any* branch.

Naturally then branch_1 would be created with F as a starting point, so that would be the tail of branch_1.

And once again, even though F is part of both branch_1 and branch_2, it's the tail of branch_1 *only*.

This is a convoluted way of saying: the tail of a branch is the point where that branch was created.

> "fork" would be more descriptive IMHO?

As you can see from the example above, the tail doesn't necessarily have to be a fork-point.

Not to mention that there can be multiple forks after the tail (e.g. B and F).

Show 8 quoted lines
> Also, if that is to save the user from looking up fork points, maybe 
> extend the syntax
>    branch_1@{fork:branch_2}
>    branch_1@{fork:master}
> 
> Depending on some of the answers to the above
>    branch_1@{fork}
> nearest fork, or upstream fork?

Except it's not necessarily a fork, nor the nearest, nor related to upstream...

So it's not a fork.
It can be literally any commit.
Cheers.
-- 
Felipe Contreras
Previous: MartinNext: Martin
Message 14 of 103 in “PATCH: improve git switch documentation”
  1. MartinJun 29, 2021
  2. Junio C HamanoJun 29, 2021
  3. MartinJun 29, 2021
  4. Junio C HamanoJun 29, 2021
  5. MartinJun 30, 2021
  6. Junio C HamanoJun 30, 2021
  7. MartinJul 1, 2021
  8. Sergey OrganovJul 1, 2021
  9. Felipe ContrerasJul 7, 2021
  10. Sergey OrganovJul 7, 2021
  11. What actually is a branch?Felipe Contreras, Jul 7, 2021
  12. Sergey OrganovJul 7, 2021
  13. MartinJul 7, 2021
  14. Felipe ContrerasJul 8, 2021
  15. MartinJul 8, 2021
  16. Felipe ContrerasJul 8, 2021
  17. MartinJul 8, 2021
  18. Felipe ContrerasJul 8, 2021
  19. MartinJul 8, 2021
  20. Felipe ContrerasJul 9, 2021
  21. MartinJul 9, 2021
  22. Felipe ContrerasJul 9, 2021
  23. switch requires --detach [[Re: What actually is a branch]]Martin, Jul 9, 2021
  24. Felipe ContrerasJul 9, 2021
  25. Randall S. BeckerJul 9, 2021
  26. Felipe ContrerasJul 9, 2021
  27. MartinJul 9, 2021
  28. Sergey OrganovJul 10, 2021
  29. Felipe ContrerasJul 10, 2021
  30. MartinJul 9, 2021
  31. Felipe ContrerasJul 9, 2021
  32. MartinJul 9, 2021
  33. Felipe ContrerasJul 9, 2021
  34. MartinJul 9, 2021
  35. Felipe ContrerasJul 10, 2021
  36. MartinJul 10, 2021
  37. Felipe ContrerasJul 10, 2021
  38. Naming the --forec option [[Re: PATCH: improve git switch documentation]]Martin, Jul 10, 2021
  39. Felipe ContrerasJul 10, 2021
  40. MartinJul 11, 2021
  41. Felipe ContrerasJul 12, 2021
  42. MartinJul 10, 2021
  43. Felipe ContrerasJul 10, 2021
  44. MartinJul 11, 2021
  45. Sergey OrganovJul 11, 2021
  46. Felipe ContrerasJul 12, 2021
  47. MartinJul 12, 2021
  48. Felipe ContrerasJul 12, 2021
  49. MartinJul 12, 2021
  50. Felipe ContrerasJul 12, 2021
  51. Sergey OrganovJul 11, 2021
  52. MartinJul 11, 2021
  53. Sergey OrganovJul 11, 2021
  54. MartinJul 11, 2021
  55. Felipe ContrerasJul 12, 2021
  56. Sergey OrganovJul 10, 2021
  57. Bagas SanjayaJul 10, 2021
  58. MartinJul 10, 2021
  59. Sergey OrganovJul 10, 2021
  60. Felipe ContrerasJul 10, 2021
  61. Sergey OrganovJul 11, 2021
  62. MartinJul 11, 2021
  63. Sergey OrganovJul 11, 2021
  64. MartinJul 11, 2021
  65. Sergey OrganovJul 11, 2021
  66. Sergey OrganovJul 11, 2021
  67. Kerry, RichardJul 12, 2021
  68. Sergey OrganovJul 12, 2021
  69. Felipe ContrerasJul 12, 2021
  70. Felipe ContrerasJul 12, 2021
  71. MartinJul 12, 2021
  72. Felipe ContrerasJul 12, 2021
  73. Sergey OrganovJul 12, 2021
  74. Felipe ContrerasJul 12, 2021
  75. MartinJul 13, 2021
  76. Felipe ContrerasJul 10, 2021
  77. Felipe ContrerasJul 10, 2021
  78. Sergey OrganovJul 11, 2021
  79. Felipe ContrerasJul 12, 2021
  80. Sergey OrganovJul 13, 2021
  81. Felipe ContrerasJul 13, 2021
  82. Sergey OrganovJul 14, 2021
  83. Felipe ContrerasJul 14, 2021
  84. Sergey OrganovJul 14, 2021
  85. Felipe ContrerasJul 8, 2021
  86. Sergey OrganovJul 8, 2021
  87. Felipe ContrerasJul 8, 2021
  88. Junio C HamanoJul 1, 2021
  89. MartinJul 1, 2021
  90. Sergey OrganovJul 1, 2021
  91. Felipe ContrerasJul 7, 2021
  92. Felipe ContrerasJul 7, 2021
  93. Felipe ContrerasJul 7, 2021
  94. Matt RogersJul 1, 2021
  95. MartinJul 13, 2021
  96. Felipe ContrerasJul 13, 2021
  97. MartinJul 16, 2021
  98. MartinJul 16, 2021
  99. Felipe ContrerasJul 16, 2021
  100. MartinJul 17, 2021
  101. MartinJul 17, 2021
  102. MartinJul 17, 2021
  103. Felipe ContrerasJul 19, 2021

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.