mayleficent
mayleficent

Reputation: 147

How can I create a master branch based off of a gh-pages branch?

I have cloned a Jekyll theme that only has the branch gh-pages. I have completely customized the theme by pushing all my changes to that gh-pages branch. And now I wonder can I create a master branch from that gh-pages branch, and if I can, how would I do it?

I hope my question make sense because I am new to git.

Upvotes: 2

Views: 73

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521997

To create a new local master branch based on the local gh-pages branch, you can use these commands:

git checkout gh-pages     # switch to the gh-pages branch
git branch -d master      # delete current (old) local master branch
git checkout -b master    # create new master from gh-pages and switch to it

Keep in mind that the second command will delete your local master branch to make room for the new one you wish to create. So if you already have a local master branch you should make sure you really want to replace it.

If you want to create a new local master branch based on the remote gh-pages branch, you can use these commands:

git checkout gh-pages                     # switch to the gh-pages branch
git branch -d master                      # delete current (old) local master branch
git checkout -b master origin/gh-pages    # create new master from gh-pages

Upvotes: 1

Maximillian Laumeister
Maximillian Laumeister

Reputation: 20359

First make sure you have the gh-pages branch checked out to the latest commit:

git checkout gh-pages

Then create a new master branch based on the current branch:

git checkout -b master

Now if you only wanted the master branch locally, you're done. If you want it on the origin as well (on GitHub), push it like this:

git push origin master

Afterwards, if you want to delete the gh-pages branch locally, run:

git branch -d gh-pages

Then if you want to delete the gh-pages branch from remote (GitHub), run:

git push origin :gh-pages

Upvotes: 1

Related Questions