How to Host a Website on GitHub For Free?
🚀 Step 1: Create a GitHub Account
If you don't have a GitHub account, create one using GitHub Signup.
🌟 Step 2: Create a New Repository
- Go to GitHub and log in.
- Click on the "+" (top-right) → Select "New repository".
- Enter a repository name (e.g.,
my-website
). - Choose "Public" (must be public to use GitHub Pages for free).
- Check "Add a README file" (optional).
- Click "Create repository".
📂 Step 3: Upload Your Website Files
There are two ways to add files:
Method 1: Upload Files Manually (GUI Method)
- Open your repository on GitHub.
- Click "Add file" → "Upload files".
- Drag and drop your website files (
index.html
,style.css
, etc.). - Click "Commit changes".
Method 2: Upload Files Using Git (Command Line Method)
If you have Git installed, use the terminal/command line:
🔹 First, install Git (if not installed)
- Windows: Install from git-scm.com
- Mac: Git is pre-installed, or installed via Homebrew:
🔹 Push Files to GitHub Using Git
- Open Terminal (Mac/Linux) or Git Bash (Windows).
- Navigate to your project folder:
- Initialize Git and link to GitHub:
- Add all files and commit:
- Push the files to GitHub:
🌍 Step 4: Enable GitHub Pages
- Open your GitHub repository.
- Click "Settings" (top right).
- Scroll down and click "Pages" (left sidebar).
- Under "Branch", select
main
, then click "Save". - Wait a few minutes, then GitHub will provide your website link:
🛠 Step 5: Test Your Website
- Open the GitHub Pages URL in a browser.
- If it's not working, wait 5–10 minutes and refresh.
- If you see a 404 error, ensure you have a
index.html
file in your repository.
🌎 Step 6: (Optional) Use a Custom Domain
If you want to use your own domain (yourdomain.com
), follow these steps:
1️⃣ Add a CNAME File
- In your repository, click "Add file" → "Create new file".
- Name it
CNAME
(no extension). - Inside the file, add your domain:
- Click "Commit changes".
2️⃣ Configure DNS Settings
Go to your domain provider (e.g., GoDaddy, Namecheap, Cloudflare).
Add the following A records pointing to GitHub Pages servers:
Add a CNAME record:
- Name:
www
- Value:
your-username.github.io
- Name:
Save changes and wait a few hours for DNS propagation.
🎉 Done! Your Website is Live!
👉 Open https://your-username.github.io/my-website/
in a browser to see your site. 🚀
💡 Troubleshooting Tips
Website Not Loading?
- Wait 5-10 minutes, then refresh.
- Check if the repository has an
index.html
file. - Ensure GitHub Pages is enabled in Settings.
Custom Domain Not Working?
- Double-check DNS settings.
- Wait a few hours for DNS propagation.
- Remove and re-add the
CNAME
file.
This should help you host your website for free on GitHub. Let me know if you need help with a specific project type! 🚀