Overview
GitHub Pages provides free hosting for static websites directly from your GitHub repository. This guide walks you through deploying your Psi Lime Portfolio to GitHub Pages.Prerequisites
Configuration
Update Vite Configuration
For GitHub Pages, you need to configure the base path invite.config.js:
Update Router Configuration
If using React Router, ensure your basename matches the base path:src/main.jsx
import.meta.env.BASE_URL automatically uses the base value from your Vite config.Deployment Steps
Configure Repository Settings
- Go to your GitHub repository
- Click Settings → Pages
- Under Source, you’ll configure this after the first deployment
Build the Project
Create a fresh production build:This generates optimized files in the
dist folder.Deploy to GitHub Pages
Run the deploy command:This command:
- Takes the contents of the
distfolder - Pushes it to the
gh-pagesbranch - Automatically creates the branch if it doesn’t exist
Enable GitHub Pages
After the first deployment:
- Go to Settings → Pages
- Under Source, select Deploy from a branch
- Under Branch, select
gh-pagesand/ (root) - Click Save
Verify Deployment
Your site will be available at:- User repository:
https://yourusername.github.io/ - Project repository:
https://yourusername.github.io/your-repo-name/
The first deployment may take 5-10 minutes. Subsequent deployments are usually faster (1-2 minutes).
Automated Deployment with GitHub Actions
For automatic deployments on every push, create.github/workflows/deploy.yml:
.github/workflows/deploy.yml
With GitHub Actions, you need to change the Pages source to GitHub Actions instead of Deploy from a branch in repository settings.
Custom Domain Setup
To use a custom domain with GitHub Pages:Add CNAME file
Create a This file will be copied to
public/CNAME file with your domain:public/CNAME
dist during build.Configure DNS
Add DNS records with your domain provider:For apex domain (example.com):For subdomain (www.example.com):
Troubleshooting
404 Error on Page Refresh
React Router requires special handling for GitHub Pages. Create apublic/404.html:
public/404.html
public/index.html, add before other scripts:
Assets Not Loading
Ensure thebase path in vite.config.js matches your repository structure:
Deploy Command Fails
Ifnpm run deploy fails:
-
Check remote URL:
-
Ensure you have push permissions:
-
Clear gh-pages cache:
CNAME File Gets Deleted
Always place yourCNAME file in the public/ folder, not in dist/. The public folder contents are automatically copied during build.
Permission Denied Error
If you get permission errors:- Generate a personal access token on GitHub
- Use it as your password when prompted
- Or configure SSH authentication:
Updating Your Deployment
To deploy updates:You can deploy without pushing to main first. The
deploy script only pushes the built files to the gh-pages branch.Next Steps
Building for Production
Learn more about optimizing your production builds
Custom Domain
Official GitHub Pages custom domain documentation