News for hackers. Stuff that matters.
Re:Git Branches: Intuition and Reality by skrebbel on Thursday November 23, 2023 @12:01PM (#38394836)
For years I was deeply annoyed by the terrible name “branch” for something that acts more like a bookmark (or “wandering tag” indeed!).

And then I learned that git branches are branches in exactly the same way that the first element of a linked list in C “is” the linked list. Git was made by C people and they’re used to referring to entire data structures by way of some root element.

I mean that doesn’t make me dislike the name any less but at least now I see where they were coming from.

Re:Git Branches: Intuition and Reality by mr_mitm on Thursday November 23, 2023 @12:30PM (#38395165)
When the entire structure of commits is called a tree, I find the name "branch" fitting. The branch is identified by its head commit, so the path from head to root is uniquely defined and that's the branch. (Disregarding merges for now.)
Re:Git Branches: Intuition and Reality by cpeterso on Thursday November 23, 2023 @03:08PM (#38396956)
Leaning into the tree metaphor (and following the precedent of other version control systems), git should have used the term trunk instead of master or main.
Re:Git Branches: Intuition and Reality by hnarn on Thursday November 23, 2023 @04:23PM (#38397734)
Why? That would heavily imply that master/main is somehow technically different from all other branches (since a trunk is certainly not a branch), which to my knowledge is not true.
Re:Git Branches: Intuition and Reality by cpeterso on Friday November 24, 2023 @06:25PM (#38409517)
I see what you mean, but don't "master" and "main" also imply some special authority? Trunk-based development with branches forking off and merging back into the trunk (a DAG, unlike a real tree! :) is an extremely common workflow.

https://trunkbaseddevelopment.com/

Re:Git Branches: Intuition and Reality by Kuraj on Thursday November 23, 2023 @07:54PM (#38399605)
By following this metaphor, a trunk would be the original commit, whereas branches are the tree branch tips.
Re:Git Branches: Intuition and Reality by galaxyLogic on Thursday November 23, 2023 @08:24PM (#38399795)
And consider that because every folder can have its own .git subfolder, we can have several paralle trunks/repositories at the same time, meaning we have a forest.

I haven't really seen specific guidelines as to when and why should anyone start a new repo. Are there some? Or is "mono-repo" the best solution, and when and for whom. Surely we need more than one git-repo in the whole world?!

Re:Git Branches: Intuition and Reality by TeMPOraL on Thursday November 23, 2023 @12:43PM (#38395305)
> Disregarding merges for now.

Without disregarding them, it's not a tree, but a DAG.

Re:Git Branches: Intuition and Reality by dayjaby on Thursday November 23, 2023 @04:42PM (#38397900)
It is a tree. What makes you think it's just a DAG? Are there commits with multiple parent commits or what?
Re:Git Branches: Intuition and Reality by zaphar on Thursday November 23, 2023 @04:48PM (#38397939)
There absolutely can be. Merge commits have multiple parent commits for example. It's definitely a graph not just a tree.
Re:Git Branches: Intuition and Reality by dayjaby on Thursday November 23, 2023 @05:41PM (#38398479)
Parent comment was about disregarding merge commits.
Re:Git Branches: Intuition and Reality by zaphar on Thursday November 23, 2023 @07:21PM (#38399381)
You can't disregard merge commits. It's part of the structure.
Re:Git Branches: Intuition and Reality by imron on Thursday November 23, 2023 @04:47PM (#38397935)
Yes. Merge commits have two parents.
Re:Git Branches: Intuition and Reality by Izkata on Thursday November 23, 2023 @05:15PM (#38398205)
Two or more. I'm not sure there's a limit.

Try not to do this (imagine a 5-way merge conflict).

Re:Git Branches: Intuition and Reality by skrebbel on Thursday November 23, 2023 @03:11PM (#38396986)
FWIW “tree” has a specific, different meaning in Git. It’s a file tracking the contents of a directory.
Re:Git Branches: Intuition and Reality by lmm on Thursday November 23, 2023 @08:10PM (#38399710)
Well yes if you disregard the thing that makes it not a tree then it is a tree. But you can't disregard that!
Re:Git Branches: Intuition and Reality by neuromanser on Thursday November 23, 2023 @12:06PM (#38394899)
That's (most probably) where the "head" terminology comes from, too.
Re:Git Branches: Intuition and Reality by alfredpawney on Thursday November 23, 2023 @02:38PM (#38396611)
Yes you are correct. It traces back to Allen Newell
Re:Git Branches: Intuition and Reality by ajross on Thursday November 23, 2023 @12:56PM (#38395452)
> Git was made by C people and they’re used to referring to entire data structures by way of some root element.

FWIW this is actually backwards. The word "branch" was already in common use (to refer to the same basic idea) in SCM systems going back decades, and in almost all of those a "branch" was indeed a first class object with its own data that acted as a "container" for commits, both semantically and physically.

The fact that a "branch" is just a pointer is in fact a git innovation on top of the former idea.

Re:Git Branches: Intuition and Reality by cpeterso on Thursday November 23, 2023 @03:05PM (#38396915)
> acts more like a bookmark

In fact, Mercurial uses the term “bookmark” for its lightweight, git-like branching. Mercurial’s branches have slightly different semantics and can’t be deleted like bookmarks or git branches

Re:Git Branches: Intuition and Reality by imron on Thursday November 23, 2023 @04:49PM (#38397954)
> Git was made by C people

This is why I think of branches as pointers. The file contents are literally just a pointer to a commit on the DAG.

Re:Git Branches: Intuition and Reality by OJFord on Thursday November 23, 2023 @07:56PM (#38399613)
I don't see the problem?

Real natural tree branches grow.

If you move the branch to point somewhere else, then it's better/more accurately said that you changed the name to refer to a different branch. We can think of branches as the chains of commits; it's the names we give them that 'wander' both as we commit and if we move them to a different branch. But merging (as it were!) the concepts of branches and names for their tips is convenient, and often equivalent/inconsequential.