git branch: gh-pages

后端 未结 9 915
北荒
北荒 2020-12-07 10:43

I have a repo on GitHub. Recently I have discovered GitHub\'s pages and I want to use them.
I would like to create this new branch and then, when I need to, either commi

9条回答
  •  太阳男子
    2020-12-07 11:32

    Are your gh-pages and master branch having EXACTLY the same folder structure? If this is the case why do you even want to have two branches? just maintain one gh-pages branch! but if for whatever reason you want to have both branches that are constantly synced then your best bet is to use git rebase. See here:
    http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/

    You can also cherry pick only the files you need from master and push them onto gh-pages using a special use case of git checkout. See here:
    http://oli.jp/2011/github-pages-workflow/#gh-pages-workflow
    http://nicolasgallagher.com/git-checkout-specific-files-from-another-branch/

    Having had to tackle with the same problem I've come to find that gh-pages will usually end up having a different code base than master. In other words, gh-pages should only include the content of the dist/build/publish folder of your project whereas master will include your config files, unminified scripts and styles etc.

    My suggestion would be to create gh-pages as an --orphan branch and only include the publication-ready material in it. You would have to clone from your master in a different local directory, use git checkout --orphan gh-pages to create gh-pages and then delete all the unnecessary files using git rm -rf .. From there you can go on and push to gh-pages after having added your publish-only files. Refer to Github docs for more info:
    https://help.github.com/articles/creating-project-pages-manually/

    Good luck

提交回复
热议问题