git root branches… how do they work?



I was reading up on and one thing caught my eye:

If you create a new root branch named gh-pages in your repository, any content pushed there will be published to [url]

I searched everywhere for information about root branches, but there don’t seem to be many resources on this. Does anybody know how to best explain what root branches are?

My current understanding is that if there are two root branches, they essentially represent two ‘repositories’ within one repository. Is this accurate?


The steps given in the link you mentioned tell you how to create one:

$ cd /path/to/fancypants
$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm .git/index
$ git clean -fdx

A root branch is basically a “branch” that is started as an orphan and has no previous history. While every repo starts with a master and the branches are branched off from that, a root branch will not be branched off from master ( of course there are repos with no master, renamed master etc, but master is the common case) and have its own history. Conceptually, yes, it is like two repos in a repo.

In the above steps, the gh-pages is created as a root branch.

Also see my answer here: How do I create a commit without a parent in Git?

Answered By – manojlds

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More