Deploying to GitHub Pages via CLI
-
Install Git
Ensure that Git is installed on your system. You can download it from git-scm.com.
-
Initialize a Local Repository
Open your terminal and navigate to your project directory:
cd /path/to/your/projectInitialize a new Git repository:
git init -
Commit Your Code
Add your files to the repository and commit them:
git add .
git commit -m "Initial commit" -
Create a GitHub Repository
Log in to your GitHub account and create a new repository. Do not initialize it with a README or any other files.
-
Add Remote Origin
In the terminal, add the remote repository:
git remote add origin https://github.com/yourusername/yourrepository.git -
Push to GitHub
Push your code to the
mainbranch:git push -u origin main -
Enable GitHub Pages
- Go to your repository on GitHub.
- Click on Settings > Pages.
- Under Source, select
mainbranch and root directory (/). - Click Save.
Setting Up a Custom Domain on GitHub Pages
-
Add a
CNAMEFileIn your project directory, create a file named
CNAME(no extension) and add your custom domain inside:yourdomain.comCommit and push this file:
git add CNAME
git commit -m "Add custom domain"
git push -
Configure DNS Records
Log in to your domain registrar (e.g., GoDaddy, Namecheap) and set up the following DNS records:
- A Records:
Host Points to @ 185.199.108.153 @ 185.199.109.153 @ 185.199.110.153 @ 185.199.111.153 - CNAME Record:
Host Points to www yourusername.github.io
- A Records:
-
Enforce HTTPS
- Go back to your GitHub repository settings under Pages.
- Make sure your custom domain is correctly listed.
- Check the option Enforce HTTPS.
Now your website should be live at your custom domain using GitHub Pages!