Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
🧭 What You’ll Learn
In this chapter, you’ll learn:
🚀 What Is Deployment?
Deployment is the process of taking your local or
staged website and making it publicly accessible via the internet. With GitHub
Pages, you’re hosting a static site by simply pushing your files to a
GitHub repo and enabling a few settings.
✅ Deployment Types with GitHub
Pages
Type |
URL Format |
Repo Name
Requirement |
User/Org Site |
https://username.github.io/ |
Must be
username.github.io |
Project Site |
https://username.github.io/repo-name/ |
Any repo name
allowed |
🔧 Step-by-Step: Enabling
GitHub Pages
Let’s assume you’ve already created your repository and
uploaded the static site files (see Chapter 2). Here’s how to go live:
🪜 Enable GitHub Pages
GitHub will now start publishing your site.
⏳ Wait Time
“Your site is live at https://username.github.io/repo-name/”
📂 Deployment Options:
Root vs. /docs Folder
Setting |
Description |
When to Use |
Root (/) |
Deploys site from root
directory (index.html at root) |
For simple static
sites |
/docs folder |
Deploys from
a folder inside the repo (e.g., myproject/docs/) |
For
multi-purpose repos (code + documentation) |
📝 If you're using the
/docs folder, make sure index.html is inside it.
💻 Sample index.html File
for Testing
html
<!DOCTYPE
html>
<html>
<head>
<title>Hello GitHub
Pages</title>
<meta charset="UTF-8" />
</head>
<body>
<h1>Hello World</h1>
<p>This is my first GitHub Pages
site!</p>
</body>
</html>
Place this in the root (or /docs) and follow the deployment
steps.
🌐 Accessing Your Deployed
Site
After successful deployment, your site will be accessible
at:
text
https://yourusername.github.io/repository-name/
Example:
https://johnsmith.github.io/portfolio/
For user sites, if your repo is named
johnsmith.github.io, then the site is at:
text
https://johnsmith.github.io/
🧪 Testing Deployment
After publishing:
🛠️ Troubleshooting
Common Deployment Issues
Issue |
Possible Cause |
Solution |
404 Not Found |
No index.html, wrong
folder selected |
Ensure correct source
folder and filename |
Styles or JS not loading |
Incorrect
file paths |
Use relative
paths, e.g., css/style.css |
Deployment delayed |
GitHub caching or
config issues |
Refresh or wait a few
minutes |
No HTTPS |
HTTPS not
enforced |
Go to Settings
> Pages and check HTTPS box |
Domain not
resolving |
DNS misconfigured or
missing CNAME |
Update domain DNS and
create CNAME file |
🌍 Custom Domain
Configuration (Optional)
Want to use www.yoursite.com instead of username.github.io?
🪜 Steps to Add a Custom
Domain
lua
yourusername.github.io
www.yoursite.com
GitHub will detect the domain and serve your site over HTTPS
(may take up to 24 hrs).
🌐 Domain Record Types
Record Type |
Hostname |
Points To |
Use Case |
A Record |
@ |
GitHub IPs (e.g.,
185.199.108.153) |
For apex domains like
mysite.com |
CNAME |
www |
username.github.io |
For
subdomains like www.mysite.com |
🔁 Automating Deployment
with GitHub Actions (Preview)
For advanced users, you can use GitHub Actions to
automate builds and deployments for static site generators like React, Vue,
Jekyll, or Hugo.
✅ Sample GitHub Actions Workflow
Create .github/workflows/deploy.yml:
yaml
name:
Deploy to GitHub Pages
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: echo "Deploying static
site..."
- run: cp -R ./build/* ./docs/
- run: git add .
- run: git commit -m "Auto-deploy
site"
- run: git push
This is a basic setup for pushing build output to /docs.
🧼 Clean Deployment
Checklist
Task |
✅ Done |
Repo created and
public |
✅ |
index.html at root or /docs |
✅ |
GitHub Pages
enabled |
✅ |
HTTPS enforced |
✅ |
Custom domain
(optional) set |
✅ |
Tested on live URL |
✅ |
📊 Table: Deployment
Settings Summary
Setting |
Value |
Source |
main branch |
Folder |
/ (root) or
/docs |
HTTPS |
Enabled |
URL Format |
https://username.github.io/ |
Custom Domain File |
CNAME |
🧠 Pro Tips
🧾 Summary
In this chapter, you learned:
You’ve officially published your first live
website! 🎉
In the next chapter, we’ll explore advanced customization, themes, and using
Jekyll.
Answer:
GitHub Pages is a free hosting service by GitHub that allows you to publish
static websites directly from a GitHub repository. It works by serving the
HTML, CSS, JS, and other static files from your repo to a web URL like
https://yourusername.github.io/.
Answer:
Yes, GitHub Pages is completely free. There are no hidden fees, and you can
host as many static sites as you want as long as your repository is public.
Private repo hosting is available with GitHub Pro.
Answer:
You can host static websites, such as portfolios, documentation, blogs,
resumes, and simple landing pages. It does not support server-side languages
like PHP, Python, or databases.
Answer:
Your site should have an index.html file in the root directory (or /docs if
using that folder). This acts as the homepage for your site.
Answer:
Typically, your site is live within 30 seconds to 2 minutes after
enabling GitHub Pages. However, DNS changes (like custom domains) may take up
to 24 hours.
Answer:
Yes! You can map a custom domain by updating your DNS settings and adding a
CNAME file to your repository with your domain name in it (e.g.,
www.yoursite.com).
Answer:
Yes, you can build your project and push the static build/ folder to
your GitHub repo. Some projects use the /docs folder for this or deploy using
GitHub Actions for automation.
Answer:
Check if your file paths are correct and relative (e.g., ./style.css instead of
/style.css). Also, make sure your files are in the correct directories and
committed to the repo.
Answer:
You can only host public repos for free with GitHub Pages. For private repo
hosting, you’ll need a GitHub Pro plan or use GitHub Actions to deploy
elsewhere (like Netlify).
Answer:
Other free static hosting options include:
These services offer more flexibility for dynamic apps,
CI/CD, and advanced routing.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)