Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should git orphaned branches be used?

Tags:

git

Git can host multiple DAGs in the same repo with git checkout --orphan command. A frequently cited use case this feature of git is to keep separate a branch for docs or the GitHub gh-pages orphaned branch for creating a static website.

Are there other reasons to use orphaned branches in git?

like image 363
ams Avatar asked Nov 02 '12 20:11

ams


People also ask

What is the use of orphan branch in git?

If you want to share your branch with someone else with no history, you can do that by creating an orphan branch. An orphan branch is a separate branch that starts with a different root commit. So the first commit in this branch will be the root of this branch without having any history.

What is git checkout orphan?

The core use for git checkout --orphan is to create a branch in a git init -like state on a non-new repository. Without this ability, all of your git branches would have a common ancestor, your initial commit. This is a common case, but in no way the only one.

What is an orphaned commit?

Your commits aren't gone (yet) When you use --force, you are adding new commits to Git and updating the branch reference of your branch. You have only orphaned the existing previous line of work as it is no longer referenced by anything.

What does git branch Branch_name do?

Git branch_name Branch is a beauty of git. You can work with coworkers without any interference with them. This will create a local branch with the name branch_name . Then you can switch your branch to this by git checkout branch_name .


2 Answers

Another possible use of this is for combining multiple repositories into one. A few examples:

  • http://www.gelato.unsw.edu.au/archives/git/0506/5511.html
  • http://jasonkarns.com/blog/merge-two-git-repositories-into-one/
  • Combining multiple git repositories

In these cases you will have two separate DAGs in the same repository before they are merged into a single unified tree. Thus this is not as much a long-term use, but an action that will temporarily pass through the state of having separate DAGs in the same repository.

like image 126
Peter Olson Avatar answered Oct 06 '22 14:10

Peter Olson


Another use case by the git online documentation:

This can be useful when you want to publish the tree from a commit without exposing its full history. You might want to do this to publish an open source branch of a project whose current tree is "clean", but whose full history contains proprietary or otherwise encumbered bits of code.

like image 37
toraritte Avatar answered Oct 06 '22 12:10

toraritte