GitHub Pages
You can use GitHub Pages to showcase some open source projects, host a blog, or even share your resume. This will guide you to get started on creating your next website.Github-pages
It will create a website with a domain, username.github.io
. Eg. Let's consider your username
as peter101 and your repo
name as OnTheGo. Then it will make a website with the domain peter101.github.io/OnTheGo/
.
Steps for the Deployment
The following steps must be followed in serial-wise.
We will create a seperate gh-pages
branch that will contain our /dist folder.
Push your code to your repository (using Terminal)
- cd to your Vite App.
- Run the following commands in your Terminal
$ git init
$ git add .
$ git commit -m "first-commit"
$ git branch -M main
$ git remote add origin http://github.com/username/repo-name.git
$ git push -u origin main
Now, you will able to see your code in your repository.
Deploying (Static)
- Go to your
vite.config.js
file. And add your base url to it.
To be more precise, your base url will be /repo-name/.
In my case, my repo-name
is Tech-To
. So, my base url will be /Tech-To/.
- Run
npm run build
in your Terminal.
By default, the build output will be placed at dist. You may deploy this dist folder to any of your preferred platforms.
- Add /dist folder into your repo. By running. ```
$ git add dist -f
`-f` is required, as your **.gitignore** will not consider your _/dist_ folder. Hence, it is required for git to consider it as well.
4. Run `$ git commit -m "Adding dist"` in your Terminal.
5. Run `$ git subtree push --prefix dist origin gh-pages`
##Your Deployed website
- Visit your repository.
- Go to Settings.
- Scroll down to **Pages**.
- There will be a link to your website.
####You did it!!


>#####Thank You for referring to this post. Your comments will be helpful for the betterment of this post.
Oldest comments (35)
OMG I just want to say a Huge thanks to you. I have been struggling past 3 days deploying my vite app to gh-pages. You saveed my life.
I have also encountered this problem and thought of sharing this to you all . My pleasure ^_^
You saved me! Thanks
My pleasure :D
Hello Im trying to do the same but its still not working ?? can you help me out?
Try to go through the steps thoroughly from the scratch. If still unable to deploy then search it on YouTube...from there you can have a better explanation of steps.
Hi! I did everything to the letter, as indicated in your tutorial; I go to Github, check my repository, and indeed this the "main" branch with the entire project (including the "dist" folder), then I go to the gh-pages branch, and oh! problem; there are only the images (assets), and the index.html, but there are none of the components (the project, well). In setting-page, indeed there is the link, but of course when I click on it, only a blank page appears in the browser. Please, could you guide me? Thank you!
I think the problem is in your github branch , Try to do the steps in order and start the deployment again. You are pushing the files in the wrong branch i think.
Thanks a lot, man, great job! Very useful instruction!
I have a multi-page static website setup, but when i host it on GH Pages, the only page that actually gets pre-pended '/repo-name/' is index.html, when i click a link to another page, i get a 404 error because the links do not incluse the repository name on the path.
How do i fix this?
Hey, did you fix it?
If yes could you tell us how?
Please kindly add a basename attribute to your App component as shown below:
function App() {
const router = createBrowserRouter(
createRoutesFromElements(
<Route path="/" element={<Tag />}>
......................................
</Route>,
),
{ basename: '/repo-name' },
);
Thanks a lot! Adding
{ basename: '/repo-name'}
as a second argument tocreateBrowserRouter
function fixed my problem.I had added to base to vite.config and created a workflow, so the page was successfully deployed on Github pages. But when I opened it I got my custom error page, which has a Go home button. When I clicked it, it navigated back from the repo name to my main pages url 'username.github.io/' and then my page would work without the '/repo-name' in the url.
I got blank page after deploy, and i dont know why

Please help
Me too, did you solved it? i'm using Vue 2
It happened to me too. I used the first comment guy's suggestion and used
npm install gh-pages --save-dev
andgh-pages -d dist
command instead and it worked.Follow this: and make sure you create your repository as github.io so that the homepage reads as "https://.github.io/" and not https://.github.io/repo
npm install gh-pages --save-dev
add to package.json
"homepage": "https://.github.io/",
...
"scripts": {
.......keep everything unchanged, just add the following three lines in script and make sure commas are proper....
"build": "vite build",
"predeploy": "npm run build",
"deploy": "gh-pages -d dist",
...
and then run command npm run deploy
Thanks master
Thanks!!!!! Now I need to update some changes (after deploy). What should I do?
After changes just run the command
npm run deploy
thank you
Wow, Thank you so much!