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, 17:33 UTC
Message-ID
<60e736e72da68_30939020850@natae.notmuch>
In-Reply-To
<4057b3ac-a77c-0d5f-d3f4-ad781754aae4@mfriebe.de>
Martin wrote:
Show 27 quoted lines
> On 08/07/2021 05:39, Felipe Contreras wrote:
> > 
> > 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.
> 
> Ok, thanks for the all the explanation.
> 
> A word on the name "tail". IMHO really confusing. I get where it is 
> coming from.
> But a lot of people will know head and tail utilities from their shell. 
> And "tail" is the one that shows lines on the end of the file to which 
> new data is added. Which is "head" in git.
> 
> Also a tail is something that follows, but (except for rebase), the base 
> point is fixed.
> 
> 
> I think (despite my earlier comment) "base" is a better word.
> It also goes along with "git rebase" which acts on the "base".
> 
> 
> However wording around that topic probably still needs to be very careful.
> "base" must be clearly distinguished from "start". Because "start" might 
> imply that only commits from here on forward are contained, but that 
> contradicts --contains which reports root to head.

I'm not really proposing such feature at this point. I did it on 2013 just to have a solution to this problem, but I didn't push for it back then.

If I ever work on that feature again I will consider the name "base", sure, but the only reason I mentioned this @{tail} concept is to try to define in a more accurate way what a branch actually is.

Show 19 quoted lines
>  > 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.
> 
> 
> So base (tail) is the shared commit "A" on which branch_2 was created. 
> (rather than the first commit made in branch_2 which is "B")
> 
> I can see how that is needed for "git rebase" so @{base} can be used for 
> <upstream>.

Yes and no. <upstream> is where branch is rebased *to*, not where it's rebased *from*:

  git rebase --onto foo@{upstream} foo@{base} foo

This command rebases all the commits foo@{base}..foo on top of foo@{upstream}.

Another way to think of it is that you'll cherry-pick foo@{base}..foo on top of foo@{upstream}.

Show 13 quoted lines
> What happens if branch_2 is rebased?
> Will the base be set to the commit onto which the branch was rebased?
> 
> A => B => C => D => E master
>             \ => F => G  foo (base = B)
> 
> foo was created on B, then fast forwarded to C, then diverged.
> 
> 
>     git rebase --onto A  foo@{base}  foo
> 
> Now that foo diverges before B, having B as base for foo seems odd. 
> (Also A will have C' as child, So the base really is A now)
Yes, A is the new base.
Show 5 quoted lines
>     git rebase --onto E  foo@{base}  foo
> 
> In this case C is already contained in master, so it will be skipped.
> If the base is moved, then foo@{base}..foo will no longer contain C. 
> IMHO that is correct, because rebase skipped it.
The new base is E.
It's not complicated, the base is whatever --onto is.
Show 20 quoted lines
> Will there be a way to manually repoint the base?
> 
> A => B => C => D master
>        \ => E => F  foo
>                  \ => G => H  bar (base = F)
> 
> 
> If I do
> 
>    git rebase --onto master  bar@{base} bar
> 
> then the commits E and F will not be part of the rebase.
> That is fine. I must handle them before.
> 
> But if I deleted foo (or for other reasons decide E and F should be 
> handled if I rebase bar) can I make them to be included?
> Something like
> 
>    git base --repoint B  bar
> 

I did not code that, but it's something people probably would need at some point. I would do `git branch --set-base` though.

Anyway, it seems I wasn't very clear, I'm not really proposing this feature. Although I think it's something that git is missing, it would be a pain in the ass to attempt to get it merged, I have much more important features I want to get done, and those don't have much chance of being merged either.

The only reason I mentioned @{tail} (or @{base}) is to have a better mental model of what a branch is.

 1. A branch is whatever is inside `branch@{base}..branch`
 2. `branch` is the branch head (`branch@{head}`), but it's not the
    branch itself

For all intents and purposes on the git documentation the branch, the branch name, and the branch head are used interchangeably, but semantically speaking they are not the same thing.

When you change the branch head you are effectively changing the branch. If @{base} existed, then changing the base would also change the branch (although that would be a much less dangerous operation).

Does that make sense?
-- 
Felipe Contreras
Previous: MartinNext: Martin
Message 16 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.