FluepkeSchaeng
FluepkeSchaeng

Reputation: 1451

Why git branch without any ancestor

Yesterday afternoon a college of mine did the git commit seen in the picture below. I wonder how you can do such strange things in git. Normally, every branch should have an ancestor branch that exists before. At least in my understanding of git.

How is this git history possible to get and why should this be useful?

Strange Git branch

Upvotes: 4

Views: 1275

Answers (1)

VonC
VonC

Reputation: 1326872

But all branches after the first should have an ancestor.

No: you can create one or more orphan branch at any time with

git checkout --orphan newbranch

The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

In your case, check the history of the 4-x-dev-cam branch on the remote repo side, and see if its history starts with a commit without parent.

why should this be useful

  • The repo git itself has at least one orphan branch (beside master): the todo branch, in order to keep management scripts which are not part of the git sources themselves.
  • Any GitHub page projects has at least another orphan branch (beside master): gh-pages, in order to manage an website associated to your project.

Basically, any time you need, in the same repo, to manage a content which is orthogonal to your main project (management script, website to illustrate your project, ...), an orphan branch is a good way to isolate that secondary history.

In the case of the 4-x-dev-cam, one possible explanation would be a massive rewrite of the project, starting from scratch.
In that case, an orphan branch is also a good way to separate that new history from the previous branches.

Upvotes: 5

Related Questions