4

I've just been introduced to orphan nodes in Git and I was wondering what sort of potential problems I could expect with using them?

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
Adrian
  • 10,246
  • 4
  • 44
  • 110
  • Those commits will be eventually collected by garbage collector, and that, I suppose, is quite an issue. Check [the related thread](https://stackoverflow.com/questions/30088693/what-happens-to-orphaned-commits) for details. – raina77ow Jan 11 '18 at 13:01
  • 1
    @raina77ow: no, orphaned branches are not orphaned commits. Orphaned commits are commits that are not on any branch / tag. Orphaned branches are just branches that are independent from each other. Related: https://stackoverflow.com/questions/1384325/in-git-is-there-a-simple-way-of-introducing-an-unrelated-branch-to-a-repository – tkruse Jan 11 '18 at 13:21

3 Answers3

8

The subject of this question ("...multiple root nodes...") makes me suspect that you and @raina77ow are actually using "orphan" to refer to two different things. The thread to which the comments links discusses what are normally called dangling commits, while an "orphan" branch typically means a branch that doesn't share history with other branches in your repository. You can create one like:

git checkout --orphan newbranch

There's nothing inherently wrong with orphan branches. In fact, tools like GitHub Pages rely on orphan branches to manage content.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • I'm not asking if it's wrong, just if there are any gotchas. – Adrian Jan 11 '18 at 13:26
  • That's pretty much what I was answering. It's not an uncommon use case, and there aren't really any gotchas except that if you're sharing your repository with somebody they might be surprised having multiple roots, so document it obviously. – larsks Jan 11 '18 at 13:38
4

If you at some point need to merge across the branches, you'll have to use the --allow-unrelated-histories option; but it's literally as easy as adding that option to the merge command, and if you omit it git will tell you exactly what you'd need to do.

So if that counts as an issue, there's that. Otherwise, whether you have independent roots in your repo doesn't really affect much of anything functionally.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
2

It's a common situation as an example when you try to merge the histories of 2 git repositories into one. There is no big issue of having orphaned branches, other than confusion of users.

tkruse
  • 10,222
  • 7
  • 53
  • 80