1. Create Github repo
If you had not created a Github repository prior to this, go ahead and create a repo in your Github account. After creating the repo, commit all your changes and push them to the repository you have created.
If you had created your repo prior to this, also commit and push all your changes to your Github repository.
2. Install angular-cli-ghpages
Run:
$ npm i angular-cli-ghpages --save-dev
if you hadn't installed angular-cli-ghpages.
3. Run build
Run:
$ ng build --prod --base-href "https://GithubUserName.github.io/GithubRepoName/"
4. Deploy to gh-pages
Run:
$ npx angular-cli-ghpages --dir=dist/Project-name
Make sure you put the name of the project in the place of Project-name.You can find this in the angular.json file under defaultProject which is at the bottom of the file.
Now if you visit https://GithubUserName.github.io/GithubRepoName/ you should see your application running remotely,which means it has successfully been published on gh-pages.