Deploy your Angular app to GitHub Pages or Cloudflare Pages directly from the Angular CLI (ng deploy)
npm install angular-cli-ghpages[![NPM version][npm-image]][npm-url]


Deploy your Angular app to GitHub Pages, Cloudflare Pages or any other Git repo directly from the Angular CLI! π
Table of contents:
1. π Changelog
2. β οΈ Prerequisites
3. π Quick Start
4. βοΈ Installation
5. π Continuous Delivery
6. π¦ Deployment Options
- --base-href
- --build-target
- --prerender-target
- --no-build
- --repo
- --message
- --branch
- --name & --email
- --no-dotfiles
- --no-notfound
- --no-nojekyll
- --cname
- --add
- --dir
- --dry-run
7. π Configuration File
8. π
°οΈ About
A detailed changelog is available in the releases section.
angular-cli-ghpages v3 supports Angular 18 to 21.
For previous versions of Angular, use v1 or v2.
This command has the following prerequisites:
- Git 1.9 or higher (execute git --version to check your version)
- Angular project created via Angular CLI v18 or greater
- Older Angular projects can still use a v1.x version or use the standalone program. See the documentation at README_standalone.
angular-cli-ghpages compiles your app, then pushes the build output to a dedicated branch (default: gh-pages) β all with a single command: ng deploy. This branch serves as the source for your web host and works out of the box with GitHub Pages and Cloudflare Pages.
This quick start assumes that you are starting from scratch.
If you already have an existing Angular project on GitHub, skip steps 1 and 2.
1. Install the latest version of the Angular CLI globally
and create a new Angular project.
``sh`
npm install --location=global @angular/cli
ng new your-angular-project
cd your-angular-project
2. By default, the Angular CLI initializes a Git repository for you.
To add a new remote for GitHub, use the git remote add command:
`sh`
git remote add origin https://github.com/
Hints:
- Create a new empty GitHub repository first.
- Replace and with your username from GitHub and the name of your new repository.https://github.com/
- Please enter the URL into 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!
3. Add angular-cli-ghpages to your project. When you run ng deploy for the first time, the Angular CLI will prompt you to choose a deployment target β select GitHub Pages:
`sh`
ng deploy
`
Would you like to add a package with "deploy" capabilities now?
No
Amazon S3
Firebase
Netlify
β― GitHub Pages
ββ navigate β’ β select
`
Alternatively, you can install it directly via ng add angular-cli-ghpages. See the installation section for details.
4. After the installation, the same ng deploy command will build and deploy your project. Your project will be automatically built in production mode.
`sh`
ng deploy --base-href=/
Please be aware of the --base-href option. It is necessary when your project will be deployed to a non-root folder. See more details below.
5. Your project should be available at https://.
Learn more about GitHub pages on the official website.
angular-cli-ghpages can be installed via ng add.deploy
This will install the NPM package and add the necessary configuration to your angular.json file.
`sh`
ng add angular-cli-ghpages
If you have multiple projects in one workspace, you should manually define the project name:
`sh`
ng add angular-cli-ghpages --project MYPROJECTNAME
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 "personal access tokens" GH_TOKEN (which works everywhere) and the "installation access token" GITHUB_TOKEN (which is exclusively provided by GitHub actions).
In short: a 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 (or PERSONAL_TOKEN) in your CI/CD environment.GITHUB_TOKEN
For GitHub Actions, you can also use the which provides more security and requires no additional setup.
All the tokens only work if the remote repository uses the HTTPS scheme.
Tokens are generally not supported for Git over SSH.
If the current working directory is already a git repository, you don't need to specify the repository again. The current remote repository with the name origin will be used in this case.--repo
You can also override the repository setting using the option.
If you specify all the three options (--repo, --name and --email), then angular-cli-ghpages will also work in directories that are not under version control at all.
`sh`
ng deploy --repo=https://github.com/
(replace and with your username from GitHub and the name of your repository)
> βΉοΈ Note for GitHub Actions
>
> The GITHUB_TOKEN (installation access token) will only trigger a release of a new website if the action runs in a private repository. In a public repo, a commit is generated, but the site does not change. If your repo is public, you must still use the GH_TOKEN (personal access token).
- optional
- Default: undefined (string)ng deploy
- Example:
- β The tag remains unchanged in your index.htmlng deploy --base-href=/the-repositoryname/
- β The tag is added to your index.html
Specify the base URL for the application being built.
Same as 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 your own domain, the URL of your hosted Angular project will look like this:
https://your-username.github.io/the-repositoryname.--base-href
In this case you have to adjust the accordingly:
`sh`
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 --base-href.--cname
However, it is now necessary to set the parameter!
`sh`
ng deploy --cname=example.org
See the option --cname for more information!
- optional
- Default: undefined (string)ng deploy
- Example:
- β Angular project is built in production modeng deploy --build-target=test
- β Angular project is using the build configuration test (this configuration must exist in the angular.json file)
If no buildTarget is set, the production build of the default project will be chosen.buildTarget
The simply points to an existing build configuration for your project, as specified in the configurations section of angular.json.--configuration production
Most projects have a default configuration and a production configuration (commonly activated by using the option) but it is possible to specify as many build configurations as needed.
This is equivalent to calling the command ng build --configuration=XXX.--no-build
This command has no effect if the option is active.
β οΈ BREAKING CHANGE (v1)
This option was called --configuration in previous versions.
BEFORE (_does not work_):
``
ng deploy --configuration=test
NOW:
``
ng deploy --build-target=test
- optional
- Default: undefined
Specifies the Angular architect target to use for prerendering instead of buildTarget.
Target Precedence: If prerenderTarget is specified, it takes precedence over buildTarget. This option has no effect if --no-build is active.
- optional
- Default: false (boolean)ng deploy
- Example:
- β Angular project is built in production mode before the deploymentng deploy --no-build
- β Angular project is NOT built
Skip the 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 --build-target setting to have no effect.
- optional
- Default: URL of the origin remote of the current dir (assumes a Git repository)
- Example: ng deploy --repo=https://github.com/
This specifies the target repository. If none is given as an option, the repository is discovered from the current working directory.
By default, this command assumes that the current working directory is a Git repository,
and that you want to push changes to the origin remote.repo
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 option.
> βΉοΈ Hint
>
> Set an environment variable with the name GH_TOKEN / PERSONAL_TOKEN or GITHUB_TOKEN and it will be automatically added to the URL, if it uses the HTTPS schema (it must start with https://github.com).git@github.com
> Tokens are generally not supported for Git over SSH (starts with ).
Learn more about "personal access tokens" here (GH_TOKEN) and about the "installation access token" here (GITHUB_TOKEN). PERSONAL_TOKEN is an alias for GH_TOKEN.
- optional
- Default: Auto-generated commit (string)ng deploy --message="What could possibly go wrong?"
- Example:
The commit message must be wrapped in quotes if there are any spaces in the text.
Some additional text is always added to the message, if the command runs on Travis CI, CircleCI or GitHub Actions.
- optional
- Default: gh-pages (string)ng deploy --branch=master
- Example:
The name of the branch you'll be pushing to.
The default uses GitHub's gh-pages branch,main
but this can be configured to push to any branch on any remote.
You may need to change this to (or master for older repositories) if you are pushing to a GitHub organization page (instead of a GitHub user page).
- optional
- Default: value of git config user.name and git config user.emailng deploy --name="Displayed Username" --email=mail@example.org
- Example:
If you run the command in a repository without user.name or user.email Git config propertiesname
(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 and email string values to identify the committer.
- optional
- Default: Dotfiles are created (boolean true)ng deploy
- Example:
- β 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
With files starting with . are ignored.
- optional
- Default: 404.html file is created (boolean true)ng deploy
- Example:
- β A 404.html file is created by default.ng deploy --no-notfound
- β No 404.html file is created.
By default, a 404.html file is created, because this is the only known workaround for SPA routing on GitHub Pages (note: GitHub still returns HTTP 404 status, which may affect Brave browser and social previews).
> [!IMPORTANT]
> Cloudflare Pages users: You must use --no-notfound to enable native SPA routing. Cloudflare Pages only activates SPA mode when no 404.html file exists. See #178
>
> We plan to change the default behavior in a future release to better support Cloudflare Pages.
- optional
- Default: .nojekyll file is created (boolean true)ng deploy
- Example:
- β A .nojekyll file is created by default.ng deploy --no-nojekyll
- β No .nojekyll file is created.
By default, a .nojekyll file is created, because we assume you don't want to compile the build again with Jekyll.
Explanation:
By creating such a file in the root of your pages repo, you will bypass the Jekyll static site generator on GitHub Pages.
Static content is still delivered β even without Jekyll.
But now the deployment will be a bit faster.
This is also 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.
The same applies to .txt files in your assets folder: They will just disappear if Jekyll processes the build. see #160
- optional
- Default: undefined (string) β No CNAME file is generatedng deploy --cname=example.com
- Example:
-
A CNAME file will be created enabling you to use a custom domain.
More information on GitHub Pages using a custom domain.
- optional
- Default: false (boolean) β The existing files will be removed from the branch you'll be pushing to as expected.ng deploy --add=true
- Example:
-
If it is set to true, it will only add, and never remove existing files.
By default, existing files in the target branch are removed before adding new ones.
More information.
- optional
- Default: undefined (string) β Conventions will be used to guess the correct directory in your dist folder.ng deploy --dir=dist/completely-different-folder/en
- Example:
-
Overrides the directory for all published sources, relative to the current working directory.
- optional
- Default: false (boolean)ng deploy
- Example:
- β 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 repeating command-line options, you can configure them in your angular.json file under the options key of your deploy configuration. Use camelCase instead of kebab-case. Available options:
- baseHref
- buildTarget
- prerenderTarget
- noBuild
- remote
- repo
- message
- branch
- name
- email
- noDotfiles
- noNotfound
- noNojekyll
- cname
- add
- dir
- dryRun
A list of all available options is also available here.
Example:
`sh`
ng deploy --base-href=https://angular-schule.github.io/angular-cli-ghpages/ --name="Angular Schule Team" --email=team@angular.schule
becomes
`json`
"deploy": {
"builder": "angular-cli-ghpages:deploy",
"options": {
"baseHref": "https://angular-schule.github.io/angular-cli-ghpages/",
"name": "Angular Schule Team",
"email": "team@angular.schule"
}
}
Now you can just run ng deploy without all the options in the command line!
> βΉοΈ Hint
>
> You can always use the --dry-run option to verify if your configuration is right.
> The project will build but not deploy.
π¬π§ angular-cli-ghpages is brought to you by the Angular.Schule team β two Google Developer Experts (GDE) from Germany. We get you and your team up to speed with Angular through remote trainings in English! Visit angular.schule to learn more.
π©πͺ angular-cli-ghpages` wurde fΓΌr Sie entwickelt von der Angular.Schule! Wir machen Sie und Ihr Team fit fΓΌr das Webframework Angular β in offenen Gruppen oder individuellen Inhouse-Schulungen. Von den Buchautoren und Google Developer Experts (GDE) Johannes Hoppe und Ferdinand Malcher.

Β© 2017-2026
[npm-url]: https://www.npmjs.com/package/angular-cli-ghpages
[npm-image]: https://img.shields.io/npm/v/angular-cli-ghpages.svg