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

Re: What actually is a branch?

From
MMartin <git@mfriebe.de>
Date
Jul 8, 2021, 19:21 UTC
Message-ID
<155308af-42ad-b044-fb37-676251a9b7e1@mfriebe.de>
In-Reply-To
<60e736e72da68_30939020850@natae.notmuch>
On 08/07/2021 19:33, Felipe Contreras wrote:
> 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`
For this part "branch" = some series of commits.
Then this is what I would say is a common misunderstanding.

Yet that may be the difference between what people want the branch to be, and what it (afaik) technically is.

People indeed tend to thing, I branched at X, so anything before is not part of the branch. "--contains" says otherwise.

Thinking of it.

If I look at a feature branch, then my feature starts where I created the branch. I want my feature branch to represent this.

But if I look at my local master branch (or any tracking branch), I like 
to believe that it contains the same as the remote branch.
And well, if we just set the base for the local tracking branch to be 
the same as the base for the remote branch that would be fine.
But if (after diverging, due to changes pulled from remote) then, I run
    git rebase @{base} @{remote}
then rebase has to skip all the shared commits.

And since rebase also repoints the "base", my local branch then no longer contains the same as the remote.

So limiting the branch to branch@{base}..branch only works for feature branches.

So yes, what is a branch? More exactly what does it contain. Two examples, that to me suggest two answers.

Also if branch@{base}..branch  then there is a problem.
- branch@{base} is then correctly not part of the branch
- So immediately after "git switch -c branch" the branch is empty => ok
But if so, then what is the branch head at that time?
The Pointer would point the @{base}, but @base is outside the branch. So 
the pointer of the branch points outside the branch?
>   2. `branch` is the branch head (`branch@{head}`), but it's not the
>      branch itself

Well technically "branch" is the "pointer" to the head. Assuming we want "head" to be a commit? Or do we want head, to be the "branch end" after the last commit? But then still "branch is the pointer"

The only problem is: branch is too often used for "the commits contained in the branch". That is way to common to even try to stop it.

Yet, if branch is used for the content, then we do not have a good term for the pointer.

> 
> 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.

I have not proof read all the docs for this.... But I think that "branch name" and "branch head" should or could be used in a clear single meaning fashion each...

> 
> When you change the branch head you are effectively changing the branch.

Well if branch is the pointer, then you change the branch, and head is being changed. If branch is the content, then you change the head, and yes the content changes.

Previous: Felipe ContrerasNext: Felipe Contreras
Message 17 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.