This repo is to test deploying default create-react-app on Github using gh-pages
.
Hosted Github site can be accessed here: http://bklimey.github.io/react-deploy-gh
Based on:
- https://blog.logrocket.com/deploying-react-apps-github-pages/
- https://www.youtube.com/watch?v=Q9n2mLqXFpU
Note: Assuming Node.js and Git are already installed
Some commentaries are generated by ChatGPT
-
On local machine, create a new react project using
npx create-react-app "react-deploy-gh"
("react-deploy-gh"
can be other name) -
Navigate into folder
cd react-deploy-gh
-
Setup Git for project
git init
Initializes a new Git repository in the current directory, creating a new .git subdirectory that will contain all the version control information.
-
Create new empty repo called
react-deploy-gh
(can be other name) in Github -
Commit and push local repo to Github
git commit -m "first commit"
Commits the changes made to the repository, creating a new snapshot of the code in its current state. The -m option allows you to add a message describing the changes made in this commit.
git branch -M main
Renames the default branch from master to main. This is done to avoid using terminology with potentially racist connotations.
git remote add origin https://github.com/bklimey/react-deploy-gh.git
Adds a remote repository named origin with the specified URL. The remote repository is typically hosted on a platform like GitHub or GitLab, and allows you to push your local changes to a central location that can be accessed by other contributors.
bklimey
should be your Github username andreact-deploy-gh
should be your repo name.git push -u origin main
Pushes the changes to the main branch of the remote repository named origin. The -u option sets the upstream branch, so that future git push commands without specifying a branch will automatically push to the main branch of the origin remote.
-
Install
gh-pages
using
npm install gh-pages --save-dev
-
Update
package.json
by adding
"homepage": "http://bklimey.github.io/react-deploy-gh",
and
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
-
Push change to Github
-
Deploy app using
npm run deploy
-
Website can now be viewed at http://bklimey.github.io/react-deploy-gh