How to Host a Website on GitHub For Free?

How to Host a Website on GitHub For Free?

 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

  1. Go to GitHub and log in.
  2. Click on the "+" (top-right) → Select "New repository".
  3. Enter a repository name (e.g., my-website).
  4. Choose "Public" (must be public to use GitHub Pages for free).
  5. Check "Add a README file" (optional).
  6. Click "Create repository".

📂 Step 3: Upload Your Website Files

There are two ways to add files:

Method 1: Upload Files Manually (GUI Method)

  1. Open your repository on GitHub.
  2. Click "Add file" → "Upload files".
  3. Drag and drop your website files (index.html, style.css, etc.).
  4. 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:
    brew install git

🔹 Push Files to GitHub Using Git

  1. Open Terminal (Mac/Linux) or Git Bash (Windows).
  2. Navigate to your project folder:
    cd /path/to/your/project
  3. Initialize Git and link to GitHub:
    git init git remote add origin https://github.com/your-username/my-website.git
  4. Add all files and commit:
    git add . git commit -m "Initial commit"
  5. Push the files to GitHub:
    git branch -M main git push -u origin main

🌍 Step 4: Enable GitHub Pages

  1. Open your GitHub repository.
  2. Click "Settings" (top right).
  3. Scroll down and click "Pages" (left sidebar).
  4. Under "Branch", select main, then click "Save".
  5. Wait a few minutes, then GitHub will provide your website link:
    https://your-username.github.io/my-website/

🛠 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

  1. In your repository, click "Add file" → "Create new file".
  2. Name it CNAME (no extension).
  3. Inside the file, add your domain:
    yourdomain.com
  4. Click "Commit changes".

2️⃣ Configure DNS Settings

  1. Go to your domain provider (e.g., GoDaddy, Namecheap, Cloudflare).

  2. Add the following A records pointing to GitHub Pages servers:

    185.199.108.153 185.199.109.153 185.199.110.153 185.199.111.153
  3. Add a CNAME record:

    • Name: www
    • Value: your-username.github.io
  4. 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

  1. 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.
  2. 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! 🚀

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close