Git & GitHub · Publish & Automate

GitHub Pages

GitHub Pages turns a repository of HTML, CSS and JavaScript into a live website — free, with HTTPS.

Advanced 5 min Lesson 17 of 19Shows Git 2.47 and GitHub.com as of 2026. GitHub changes its layout from time to time; button names stay the same.
Before you start:Commit, Push and Pull
0/19 in Git & GitHub
On this page · 5 min · Advanced

Learning objectives#

  • Publish a static site with GitHub Pages
  • Know the user site vs project site URLs
  • Configure the source branch
  • Add a custom domain

Explanation#

A repository named <username>.github.io (asha.github.io) becomes your personal site at https://asha.github.io. Any other repository can publish a project site at https://asha.github.io/<repo>/.

Settings → Pages → Build and deployment: Source “Deploy from a branch”, branch main and folder / (root) or /docs. Save. After a minute the page shows “Your site is live at …”.

Sites built with React, Angular or Vite need a build step: choose Source “GitHub Actions” and use the suggested workflow, which builds the site and publishes the output folder.

For a custom domain, enter it under Custom domain, add the DNS records GitHub shows (CNAME for www, A records for the apex) at your registrar, and tick Enforce HTTPS.

Step-by-step screens#

Drawings of github.com, the Git installer, VS Code and a terminal. GitHub changes its layout from time to time; the button names stay the same. The red numbers match the numbered actions under each picture; names on your computer will differ.

Loading pictures…

Code example: A personal site in four commands#

ShellA personal site in four commands Illustrative
git clone https://github.com/asha/asha.github.io.git
cd asha.github.io
echo "<h1>Hi, I'm Asha</h1>" > index.html
git add index.html
git commit -m "Add home page"
git push
# Settings → Pages → Deploy from a branch → main / (root) → Save
Expected output
About a minute later https://asha.github.io shows “Hi, I’m Asha”. Every later push updates the site.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. The repository name decides the address.
  2. index.html is the home page.
  3. Push to main.
  4. Pages publishes main / (root).

Real-world use case#

A fresher hosts a portfolio on asha.github.io with links to three projects, each with its own project site and live demo.

Common mistakes#

No index.html

Pages shows the README or a 404. The home page must be named index.html.

Absolute paths in a project site

/style.css points to asha.github.io/style.css, not /hello-github/style.css. Use relative paths or set the base path in your build tool.

Best practices#

  • Use relative paths
  • Enforce HTTPS
  • Use the Actions source for build-based sites
  • Check the Actions tab if a deploy fails

Remember this#

username.github.io = personal site.

Settings → Pages → main / (root).

Every push redeploys.

Practice exercise#

Your task: Write the address of the project site for the repository hello-github owned by asha.

Show solution
Text Illustrative
https://asha.github.io/hello-github/

Mini quiz#

GitHub Pages quizMultiple choice Question 1 of 1

What must the repository be called for the site https://asha.github.io?

Score so far: 0/0

Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.