git branch: gh-pages

后端 未结 9 916
北荒
北荒 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:16

    On your local clone do,

    git symbolic-ref HEAD refs/heads/gh-pages
    rm .git/index 
    git clean -fdx
    

    Then, git checkout gh-pages and write your pages. git push origin gh-pages when you're ready to publish the pages.

    0 讨论(0)
  • 2020-12-07 11:16

    The typical way is to switch branches: git checkout master if you want to work on master and git checkout gh-pages if you want to work on gh-pages.

    Starting with git 2.5, you can have both branches checked out at the same time (in different directories). See https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows. Setup via git worktree add -b gh-pages ../gh-pages origin/gh-pages.

    Bonus: If the content of a subdirectory of your master checkout is the content of gh-pages, use the script provided at https://github.com/X1011/git-directory-deploy.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-07 11:35

    Publish a static site like this:

    git subtree push --prefix www origin gh-pages
    

    Where www is the doc root directory in which your static files are. Your static site is now live at: https://[user_name].github.io/[repo_name]/

    0 讨论(0)
  • 2020-12-07 11:36

    Creating Project Pages manually

    Adding a new set of Pages for a project manually is a straightforward process if you're used to using command-line git.

    https://help.github.com/articles/creating-project-pages-manually

    0 讨论(0)
  • 2020-12-07 11:37

    There's yet another solution to your problem: Forget about gh-pages and branching; Put your static files that are supposed to be served inside /docs directory and then go to your project settings and tell github to serve /docs content.

    For more information take a look at this

    0 讨论(0)
提交回复
热议问题