2

I am currently working on a github pages project and generate the website to a folder named dist on a branch named dev. I want to push the content of dist to the master branch. Googling around I found github subtree and I could push the dist directory to master using the command:

git subtree push --prefix dist origin master

issue is this pushes the entire directory. So master branch has one directory named dist, containing dist/index.html etc. Instead I would like to push all the content of dist to the master branch. So that the master branch contains index.html and all other content. How can this be done?

Marc
  • 626
  • 5
  • 15

1 Answers1

2

It is not easily done (beside doing some git filter-branch magic)

If you have a look at "Configuring a publishing source for GitHub Pages", you should instead generate your site directly in the gh-pages branch.

Or, you can stay in master branch, but generate in a docs/ folder instead of dist.

In both cases, GitHub pages will render that content.

However, for a User Page:

If your site is a User or Organization Page that has a repository named <username>.github.io or <orgname>.github.io, you cannot publish your site's source files from different locations.
User and Organization Pages that have this type of repository name are only published from the master branch.

In that case, reverse your workflow:

  • develop your site on a dev branch,
  • generate your site on the master branch

When you are in your dev branch, you can declare the master branch as a submodule (see here for the procedure), which will therefore be visible as a "subfolder" (for example a "dist" subfolder, except that subfolder will actually be your same Git repo, on master)

Generate your site as usual (in dist), go in dist, add, commit and push (that subfolder being a submodule, it will push on its associated branch: master)
Then go back to your project repo folder (parent of dist, currently on the dev branch), add, commit and push (to record the new state of the submodule dist)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I had some issues with merge conflicts earlier and ran the command git push origin `git subtree split --prefix docs master`:master --force which strangely worked as it just pushed the content of docs. I don't really want to run that every time however. – Marc Jan 16 '19 at 06:30
  • 1
    @Marc Sure, but subtree is not the recommended way to have a generated set of files published with GitHub pages: use one of the official documented branch or folders that I mention in the answer. – VonC Jan 16 '19 at 07:20
  • the issue is if you have a User page you can not use folders och gh-pages branch for some reason........ – Marc Jan 16 '19 at 15:43
  • 1
    @Marc Indeed: "If your site is a User or Organization Page that has a repository named `.github.io` or `.github.io` , you cannot publish your site's source files from different locations. User and Organization Pages that have this type of repository name are only published from the `master` branch." – VonC Jan 16 '19 at 15:47
  • 1
    @Marc I have edited the answer to propose an alternative which would preserve your current way of working (generating the site in a `dist` subfolder) – VonC Jan 16 '19 at 15:54