Deploy your Angular app to GitHub pages directly from the Angular CLI! 🚀
Table of contents:
- 📖 Changelog
- ⚠️ Prerequisites
- 🚀 Quick Start (local development)
- 🚀 Continuous Delivery
- 📦 Options
- 📁 Configuration File
- 🏁 Next milestones
- ⁉️ FAQ
A detailed changelog is available in the releases section.
In the past this project was a standalone program. This is still possible: See the documentation at README_standalone.
This command has the following prerequisites:
- Git 1.9 or higher (execute
git --versionto check your version)
- Angular project created via Angular CLI v8.3.0-next.0 or greater (execute
ng update @firstname.lastname@example.org @email@example.com upgrade your project if necessary)
This quick start assumes that you are starting from scratch. If you already have an existing Angular project on GitHub, skip step 1 and 2.
Install the next version of the Angular CLI (v8.3.0-next.0 or greater) globally and create a new Angular project.npm install -g @angular/cli@nextng new your-angular-project --defaultscd your-angular-project
By default the Angular CLI initializes a Git repository for you.
To add a new remote for GitHub, use the
git remote addcommand:git remote add origin https://github.com/<username>/<repositoryname>.git
- Create a new empty GitHub repository first.
<repositoryname>with your username from GitHub and the name of your new repository.
- Please enter the URL
https://github.com/<username>/<repositoryname>.gitinto your browser – you should see your existing repository on GitHub.
- Please double-check that you have the necessary rights to make changes to the given project!
angular-cli-ghpagesto your project.ng add angular-cli-ghpages
Deploy your project to GitHub pages with all default settings. Your project will be automatically built in production mode.ng deploy
Which is the same as:ng run your-angular-project:deploy
Your project should be available at
Learn more about GitHub pages on the official website.
If you run this command from a CI/CD environment, the deployment will most likely not work out of the box. For security reasons, those environments usually have read-only privileges or you haven't set up Git correctly. Therefore you should take a look at GitHub tokens. In short: a GitHub token replaces username and password and is a safer choice because a token can be revoked at any time.
All you need to do is to set an environment variable called
GH_TOKEN in your CI/CD environment.
You should also set the URL to the repository using the
The URL must use the HTTPS scheme.
ng deploy --repo=https://github.com/<username>/<repositoryname>.git --name="Your Git Username" --firstname.lastname@example.org
<repositoryname> with your username from GitHub and the name of your repository)
Please do NOT disable the silent mode if you have any credentials in the repository URL! You have to treat the GH_TOKEN as secure as a password!
ng deploy– The tag
<base href="/">remains unchanged in your
ng deploy --base-href=/the-repositoryname/– The tag
<base href="/the-repositoryname/">is added to your
Specifies the base URL for the application being built.
ng build --base-href=/XXX/
ℹ️ Please read the next lines carefully, or you will get 404 errors in case of a wrong configuration!
A) You don't want to use a custom domain
If you don't want to use an own domain, then your later URL of your hosted Angular project should look like this:
In this case you have to adjust the
ng deploy --base-href=/the-repositoryname/
B) You want to use a custom domain
If you want to use your own domain, then you don't have to adjust
However, it is now necessary to set the
ng deploy --cname=example.org
See the option --cname for more information!
- Default: URL of the origin remote of the current dir (assumes a Git repository)
ng deploy --repo=https://github.com/<username>/<repositoryname>.git
By default, this command assumes that the current working directory is a Git repository,
and that you want to push changes to the
If instead your files are not in a git repository, or if you want to push to another repository,
you can provide the repository URL in the
Set an environment variable with the name
GH_TOKEN and it will be automatically added to the URL.
https://github.com/<username>/<repositoryname>.git is changed to
if there is an environment variable
GH_TOKEN with the value
Learn more about GitHub tokens here.)
ng deploy– Angular project is build in production mode
ng deploy --configuration=test– Angular project is using the configuration
test(this configuration must exist in the
A named build target, as specified in the
configurations section of
Each named target is accompanied by a configuration of option defaults for that target.
ng build --configuration=XXX.
This command has no effect if the option
--no-build option is active.
ng deploy– Angular project is build in production mode before the deployment
ng deploy --no-build– Angular project is NOT build
Skip build process during deployment.
This can be used when you are sure that you haven't changed anything and want to deploy with the latest artifact.
This command causes the
--configuration setting to have no effect.
ng deploy --message="What could possibly go wrong?"
The commit message must be wrapped in quotes if there are any spaces in the text.
Some handy additional text is always added, if the environment variable
TRAVIS exists (for Travis CI) or
if the environment variable
CIRCLECI exists (for Circle CI).
ng deploy --branch=master
The name of the branch you'll be pushing to.
The default uses GitHub's
but this can be configured to push to any branch on any remote.
You have to change this to
master if you are pushing to a GitHub organization page (instead of a GitHub user page).
- Default: value of
git config user.nameand
git config user.email
ng deploy --name="Displayed Username" --email@example.com
If you run the command in a repository without
user.email Git config properties
(or on a machine without these global config properties),
you must provide user info before Git allows you to commit.
In this case, provide both
- Default: silent
ng deploy– Logging is in silent mode by default.
ng deploy --no-silent– Logging shows extended information.
Logging is in silent mode by default. In silent mode, log messages are suppressed and error messages are sanitized.
--no-silent option enables extended console logging.
Keep this untouched if the repository URL or other information passed to git commands is sensitive!
⚠️ WARNING: This option should be kept as it is if the repository URL or other information passed to Git commands is sensitive and should not be logged (== you have a public build server and you are using the
GH_TOKENfeature). By default the silent mode is enabled to avoid sensitive data exposure.
- Default: dotfiles
ng deploy– Dotfiles are included by default.
ng deploy --no-dotfiles– Dotfiles are ignored.
The command includes dotfiles by default (e.g.
.htaccess will be committed).
--no-dotfiles files starting with
. are ignored.
This is super useful if you want to publish a
Create such a file in the root of your pages repo to bypass the Jekyll static site generator on GitHub Pages.
Static content is still delivered – even without Jekyll.
This should only be necessary if your site uses files or directories that start with _underscores since Jekyll considers these to be special resources and does not copy them to the final site.
→ Or just don't use underscores!
undefined(string) – No CNAME file is generated
ng deploy --cname=example.com
A CNAME file will be created enabling you to use a custom domain. More information on GitHub Pages using a custom domain.
ng deploy– Normal behavior: Changes are applied.
ng deploy --dry-run– No changes are applied at all.
Run through without making any changes. This can be very useful because it outputs what would happen without doing anything.
To avoid all these command-line cmd options, you can write down your configuration in the
angular.json file in the
options attribute of your deploy project's architect. Just change the kebab-case1 to lower camel case2
ng deploy your-project-name --base-href=https://angular-schule.github.io/angular-cli-ghpages/ --name=angular --firstname.lastname@example.org
And just run
ng deploy your-project-name 😄.
--dry-run option to verify if your configuration is right.You can always use the
2. Lower camel case (part of CamelCase) is a naming convention in which a name is formed of multiple words that are joined together as a single word with the first letter of each of the multiple words (except the first one) capitalized within the new word that forms the name. "Lower Camel Case" becomes "lowerCamelCase" ↩
We are glad that we have an integration into the CLI again. However, we are looking forward to the following features:
- an interactive command-line prompt that guides you through the available options
- your feature that's not on the list yet?
We look forward to any help. PRs are welcome! 😃
Code released under the MIT license.
This project is made on top of tschaub/gh-pages.
Thank you very much for this great foundation!