How to Build a Website on Github for Beginners

in tutorialweb · 7 min read

Step-by-step guide showing how to build a website on GitHub using GitHub Pages, with commands, examples, checklists, and testing tips.

Overview

This guide explains how to build a website on GitHub and publish it with GitHub Pages. The phrase how to build a website on github appears here to help you find this practical, step-by-step tutorial. You will learn how to create a GitHub repository, set up a basic HTML, CSS, and JavaScript site, push code from your computer, enable GitHub Pages, and verify the live site.

This matters because GitHub Pages provides free hosting, Git version control, and an easy workflow for entrepreneurs, developers, and beginners to deploy simple marketing sites, portfolios, and documentation.

Prerequisites: a GitHub account, a computer with Git installed, basic familiarity with terminal or command prompt, and a text editor. Estimated total time: 1.5 to 3 hours depending on customization and domain setup.

What you will learn: repository creation, local project setup, deploying via Git, enabling GitHub Pages, adding a custom domain and HTTPS, and basic debugging. Each main step includes commands, expected outcomes, common issues, and a short checklist.

Step 1:

how to build a website on github - create a repository

Action: create a new repository on GitHub to host your site.

Why: GitHub Pages serves content from a repository branch. Creating the repo gives you the place to store HTML, CSS, and assets.

How to do it:

  1. Sign in to github.com.
  2. Click New repository.
  3. Give the repo a name, for a user site use username.github.io, for a project site use any name.
  4. Choose Public, and optionally add a README.
  5. Do not add a license or .gitignore now if you will push an existing local project.

Expected outcome: A new empty repository page with quick setup instructions and the repository URL.

Common issues and fixes:

  • Error: “Repository name already exists.” Fix: choose a unique name or delete an old repo.
  • Mistake: made repository private. Fix: make it public in Settings > Manage access if you want free Pages for public content.

Checklist:

  1. Repository created on GitHub.
  2. You can view repo URL like github.com
  3. You chose Public unless you have a paid plan and special needs.

Time estimate: ⏱️ ~10 minutes

Step 2:

set up your local project and initialize git

Action: create a local folder for your site and initialize Git, or clone the remote repo.

Why: Working locally lets you edit files, test in a browser, and use Git to track and push changes.

Commands:

git clone github.com
cd your-repo
# OR to start fresh
mkdir my-site
cd my-site
git init
git remote add origin github.com

How to do it:

  1. Open terminal or command prompt.
  2. Clone if you started repository on GitHub, or create a new folder and git init if not.
  3. Create files: index.html, styles.css, script.js. 4. Stage and commit:
git add .
git commit -m "Initial site files"
git push -u origin main

Adjust branch name if your default is master.

Expected outcome: Local project synced to GitHub, visible files on GitHub web UI.

Common issues and fixes:

  • Authentication errors: configure Git with git config --global user.name "Name" and git config --global user.email "email", and set up SSH keys or use a personal access token for HTTPS.
  • Wrong branch: check git branch and push to the branch used by GitHub Pages (often main).

Checklist:

  1. Local folder created with index.html.
  2. Git initialized and remote set.
  3. First commit pushed to GitHub.

Time estimate: ⏱️ ~15 minutes

Step 3:

create a basic HTML, CSS, and JavaScript site

Action: add core files that serve as your website.

Why: GitHub Pages serves static files like HTML, CSS, and JS. A minimal site proves the workflow and is easy to expand.

Example index.html:

How to do it:

  1. Create index.html, styles.css, script.js in your repo folder.
  2. Test locally by opening index.html in a browser.
  3. Commit changes and push with git.

Expected outcome: Files live in repository and render locally. You will later see them at your GitHub Pages URL.

Common issues and fixes:

  • CSS not loading: check correct path in link tag and case sensitivity.
  • JS errors: open browser DevTools Console to see errors and fix paths or syntax.
  • Browser caching: use hard refresh or open in incognito to test latest files.

Checklist:

  1. index.html present and valid.
  2. styles.css linked and applying styles.
  3. script.js loading without console errors.

Time estimate: ⏱️ ~20 minutes

Step 4:

enable GitHub Pages and choose a branch

Action: configure GitHub Pages to publish your site.

Why: Enabling Pages tells GitHub which branch and folder to serve as the website root.

How to do it:

  1. On GitHub, go to your repository Settings > Pages.
  2. Under Source select the branch (main or gh-pages) and folder (root or /docs).
  3. Click Save. GitHub will show the site URL, e.g., yourname.github.io

Expected outcome: Pages enabled and a published URL shown. GitHub will deploy in a minute or so.

Common issues and fixes:

  • “Your site is building” longer than expected: wait a few minutes, then refresh.
  • 404 error after enabling: ensure index.html is in the selected folder and branch.
  • Branch not available: create the branch and push it, then select it.

Checklist:

  1. Pages source selected.
  2. Published site URL displayed in repository settings.
  3. Initial deployment started.

Time estimate: ⏱️ ~10 minutes

Step 5:

add a custom domain and enable HTTPS

Action: (Optional) configure a custom domain and enforce HTTPS.

Why: A custom domain makes your site brandable and professional. Enabling HTTPS secures traffic.

How to do it:

  1. Buy or use an existing domain from a registrar.
  2. In domain DNS settings, add an A record pointing to GitHub Pages IPs for apex domains, or add a CNAME to username.github.io for subdomains.
  3. In GitHub repo Settings > Pages, enter your custom domain and save.
  4. Check “Enforce HTTPS” once GitHub issues a certificate.

Example DNS for a subdomain:

  • Type: CNAME
  • Name: www
  • Value: yourname.github.io

Expected outcome: Custom domain resolves to your GitHub Pages site and shows HTTPS lock after certificate issuance.

Common issues and fixes:

  • DNS propagation delays: changes can take up to 48 hours; use dig or nslookup to verify.
  • Mixed content warnings: ensure all resources load via https:// URLs.
  • Certificate not issued: ensure domain is correctly pointing to GitHub and wait; re-enter domain if needed.

Checklist:

  1. DNS records set at registrar.
  2. Custom domain entered in GitHub Pages settings.
  3. HTTPS enabled and enforced.

Time estimate: ⏱️ ~20 to 60 minutes (DNS propagation dependent)

Step 6:

automate deployments and add analytics

Action: add a simple CI or GitHub Action for build steps and integrate basic analytics.

Why: Automation ensures consistent deploys, and analytics helps measure traffic and conversions.

How to do it:

  1. If you use a static site generator (Jekyll, Hugo, Gatsby), add a GitHub Action workflow that builds and deploys to the pages branch.
  2. For plain static sites, you may use a simple build step to minify assets or just rely on pushing to the pages branch.
  3. Add Google Analytics or alternative by inserting script snippet into your HTML.

Example minimal GitHub Action for a static site (place in .github/workflows/deploy.yml):

Expected outcome: Automated deployment on each push, consistent site builds, and tracking of visitors.

Common issues and fixes:

  • Action fails: check workflow logs in Actions tab to see build errors.
  • Analytics not showing data: verify tracking ID and that the snippet is on all pages.

Checklist:

  1. Workflow file added and passing.
  2. Site redeploys automatically on push.
  3. Analytics script visible in page source.

Time estimate: ⏱️ ~30 minutes

Testing and Validation

Use the following checklist to confirm your site works and is discoverable.

Checklist:

  1. Visit the Pages URL shown in repository settings and confirm index.html loads.
  2. Open browser DevTools and check Console for errors and Network tab for 200 responses.
  3. Verify assets (CSS, JS, images) load without mixed content warnings.
  4. If using a custom domain, test both with and without www and verify HTTPS is active.
  5. Push a small change and confirm the site updates after deployment.

Perform these tests locally and after each push.

Time estimate for validation: ⏱️ ~10 to 20 minutes

Common Mistakes

  1. Wrong branch or folder selected for Pages. Avoid this by confirming Settings > Pages points to the branch where index.html lives.
  2. Case-sensitive paths and filenames. Web servers are case-sensitive. Keep filenames consistent and check link href values.
  3. Forgetting to commit and push. Local changes will not appear until you git add, git commit, and git push.
  4. DNS configuration errors for custom domains. Use authoritative tools like dig, nslookup, or online DNS checkers to confirm records.

Avoid these by following the checklists in each step and testing after each change.

FAQ

How Long Does Github Pages Take to Publish Changes?

Most simple updates publish within a minute or two after a successful push. If using a generator or Actions, allow extra build time; DNS changes can take up to 48 hours.

Can I Use a Private Repository for Github Pages?

GitHub Pages for private repositories requires a GitHub Pro, Team, or Enterprise plan for private Pages. Public repositories can use Pages for free.

Do I Need to Know Git to Use Github Pages?

Basic Git commands are helpful: clone, add, commit, push. You can also edit files via the GitHub web UI for minor changes without learning Git.

How Do I Use a Custom Domain with Github Pages?

Add appropriate DNS records at your registrar: CNAME for subdomains, A records for apex domains. Then enter the domain in repository Settings > Pages and enable HTTPS once issued.

What If My Site Uses Server-Side Code?

GitHub Pages only serves static sites. For server-side features, use a hosted platform like Heroku, Netlify Functions, Vercel, or a cloud provider.

Next Steps

After publishing, iterate on content and design: add SEO meta tags, mobile-responsive CSS, and structured data. Integrate a static site generator for templating and content management, and configure automated testing and preview environments using pull requests and GitHub Actions. Consider adding a CMS, contact form backend, or e-commerce integrations depending on your site’s goals.

Further Reading

Sources & Citations

Tags: github github-pages html css javascript web-development
Ryan

About the author

Ryan — Web Development Expert

Ryan helps beginners and professionals build amazing websites through step-by-step tutorials, code examples, and best practices.

Recommended Web Hosting

The Best Web Hosting - Free Domain for 1st Year, Free SSL Certificate, 1-Click WordPress Install, Expert 24/7 Support. Starting at CA$2.99/mo* (Regularly CA$8.49/mo). Recommended by WordPress.org, Trusted by over 5 Million WordPress Users.

Try Bluehost for $2.99/mo