» npm install gh-pages-cli
node.js - Why won't git bash recognize gh-pages as a valid command after npm installing gh-pages? [GatsbyJS, GitHub Pages] - Stack Overflow
Add gh prompt to set up gh pages
deployment - Error deploying Angular4 to ghpages using angular-cli-ghpages - Stack Overflow
git branch: gh-pages - Stack Overflow
» npm install gh-pages
» npm install angular-cli-ghpages
See https://www.npmjs.com/package/gh-pages#basic-usage
What you need to do is create a js script to use the module. I would suggest you create it under a scripts directory under the root of your project.
Paste the code you need to run. I recommend the following for configuring uploading to a public directory:
ghpages.publish(
'public',
{
branch: 'master',
repo: '',
},
() => {
console.log('Deploy Complete!')
}
)
Enter your repo property. => defines the callback function outputting to the console.
Next, open package.json under the root of your project directory. You will see "scripts" defined with default Gatsby scripts, you will need to add one for deployment.
Add the following at the end:
deploy:github": "npm run build && node ./scripts/deploy-github"
Save the file, execute npm run and you will see the list of scripts you can execute. Execute npm run deploy:github when you want to deploy.
If you wish to invoke gh-pages via the cli, here are two options.
Option A: Install gh-pages globally
npm install gh-pages --global
gh-pages --help
By default, npm install places packages in the local ./node_modules/ directory. By using the --global switch, you can change that behavior so you can access the command more conveniently.
global o Default: false o Type: Boolean Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See npm help folders for more on the differences in behavior. o packages are installed into the {prefix}/lib/node_modules folder, instead of the current working directory. o bin files are linked to {prefix}/bin o man pages are linked to {prefix}/share/man
Option B: Invoke gh-pages locally
npm install gh-pages --save-dev
node node_modules/gh-pages/bin/gh-pages.js --help
This same command you ran, as suggested in the Gatsby Docs. It is then followed by a direct invocation of the full path to the local gh-pages.js.
I solved this by added the following to the end of the scripts object in package.json,
"scripts": {
"deploy": "ng build --prod --base-href
https://shanegibney.github.io/mathapp/ && angular-cli-ghpages --branch
gh-pages"
}
and then ran,
$sudo npm run deploy
So it seems that what was needed was the '--branch gh-pages' as an option, but there is nothing to suggest this on the npm page for angular-cli-ghpages.
Note if running these command separately without going through package.json I found it doesn't work,
$ sudo ng build --prod --base-href https://shanegibney.github.io/mathapp/
$ sudo angular-cli-ghpages --branch gh-pages
Got help from a blog post on shermandigital.com
After git push origin master gh - page deploy step 1:"ng build --prod --base-href https://username.github.io/project-name/"
step 2: "ngh --dir dist/project-name"
replace project-name and username of with github username, project-name
More recent versions of git have an alternative to the git symbolic-ref method that Chandru explained. This avoids having to use the lower level commands.
git checkout --orphan gh-pages
git rm -rf .
You might find this tutorial useful:
Setup GitHub Pages "gh-pages" branch and "master" branch as subfolders of a parent project folder ("grandmaster").
To me this approach seems simpler then doing a git checkout gh-pages each time you want to edit your gh-pages content. Let me know what you think ^_^
Edit: I updated the tutorial link - thanks @Cawas. The old tutorial (not recommended) was https://gist.github.com/825950