I have created a Git repo for a JavaScript library. The repo also contains a demo website that uses the bundled library, which is generated in a dist/
folder. I would now like to deploy that website to GitHub Pages.
However, I have the dist/
folder in my .gitignore
and would prefer it to remain ignored.
Is there a way to automatically generate the gh-pages
branch, which should include dist/
, but keep it off the master
branch?
In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository.
The dist directory should not be committed to your version control system and should be ignored through your . gitignore as it will be generated automatically every time you run nuxt generate .
On GitHub, navigate to your site's repository. Under your repository name, click Settings. In the "Code and automation" section of the sidebar, click Pages. Under "Build and deployment", under "Source", select Deploy from a branch.
Commit this script and call it after having built your dist
:
#!/bin/sh
git commit -am "Save uncommited changes (WIP)"
git branch --delete --force gh-pages
git checkout --orphan gh-pages
git add -f dist
git commit -m "Rebuild GitHub pages"
git filter-branch -f --prune-empty --subdirectory-filter dist && git push -f origin gh-pages && git checkout -
I use it for that ;-)
To summarize your context:
master
dist/
folder that is ignored and untrackeddist/
folder on GitHub Pages using a gh-pages
branch.The simplest way to do this seems to follow the workflow suggested in this gist as well as in the documentation of Yeoman.
But note that this relies on the advanced command git subtree and requires that the dist/
folder is not ignored and tracked on master
as well.
You could then follow the doc regarding the configuration of GH Pages' publishing source.
Does this address your question or do you really want to have the two branches separated and no dist/*
file in the master
branch?
In the latter case, the problem is more complicated (because of the untracked or ignored files in the work tree that can hinder the process...) but you may want to have a look at this project, which is an alternative to the git subtree
-based solution, and is based on a Bash script.
(Note: I have not tested this "git-directory-deploy" solution; it was suggested in the gist I mentioned above.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With