<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Christian Chi</title>
    <description>The latest articles on DEV Community by Christian Chi (@halogenius).</description>
    <link>https://dev.to/halogenius</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2831468%2F524abd5e-0455-4cfc-9bf9-c175a89315e0.png</url>
      <title>DEV Community: Christian Chi</title>
      <link>https://dev.to/halogenius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/halogenius"/>
    <language>en</language>
    <item>
      <title>🚀 How to Deploy a React App on GitHub Pages</title>
      <dc:creator>Christian Chi</dc:creator>
      <pubDate>Sun, 09 Feb 2025 17:11:39 +0000</pubDate>
      <link>https://dev.to/halogenius/how-to-deploy-a-react-app-on-github-pages-3076</link>
      <guid>https://dev.to/halogenius/how-to-deploy-a-react-app-on-github-pages-3076</guid>
      <description>&lt;p&gt;GitHub Pages is a free and simple way to host your React applications. In this guide, I'll walk you through the step-by-step process of deploying your React app to GitHub Pages using &lt;code&gt;gh-pages&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, ensure you have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A GitHub account&lt;/li&gt;
&lt;li&gt;Node.js and npm installed&lt;/li&gt;
&lt;li&gt;A React project ready for deployment&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  📺 Full Tutorial on Youtube
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/LKxL-wlwTOw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Download the simple demo app used in the tutorial - &lt;a href="https://github.com/chrisHalogen/HID-Tutorials/raw/refs/heads/main/Host-React-On-Github/react-crud-project-updated.zip" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1️⃣ Create an Empty GitHub Repository
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go to GitHub and create a new repository.&lt;/li&gt;
&lt;li&gt;Name it &lt;code&gt;deploy-react-git&lt;/code&gt; (or any name you prefer).&lt;/li&gt;
&lt;li&gt;Do not initialize with a README, &lt;code&gt;.gitignore&lt;/code&gt;, or license.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2️⃣ Clone the Repository
&lt;/h2&gt;

&lt;p&gt;To clone the repository, use an access token (recommended) or SSH:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/&amp;lt;your-github-username&amp;gt;/deploy-react-git.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, navigate into the cloned repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd deploy-react-git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy your React project files into this directory.&lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;: If you want to follow the tutorial exactly, download this simple react app used in the tutorial - &lt;a href="https://github.com/chrisHalogen/HID-Tutorials/raw/refs/heads/main/Host-React-On-Github/react-crud-project-updated.zip" rel="noopener noreferrer"&gt;Click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;🔹 Need help with GitHub Access Tokens? &lt;br&gt;
Check out this tutorial: &lt;a href="https://www.youtube.com/watch?v=EX5-YlAXD3Q" rel="noopener noreferrer"&gt;How to Use GitHub Access Tokens&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  3️⃣ Install Dependencies
&lt;/h2&gt;

&lt;p&gt;Run the following command to install all required dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Non-default packages used(in the simple demo app):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sass (for SCSS styling)&lt;/li&gt;
&lt;li&gt;axios (for HTTP requests)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If they are not installed, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install sass axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4️⃣ Install &lt;code&gt;gh-pages&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Install gh-pages as a development dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5️⃣ Update &lt;code&gt;package.json&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Add a homepage field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"homepage": "https://&amp;lt;your-github-username&amp;gt;.github.io/deploy-react-git",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add deployment scripts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  "predeploy": "npm run build",
  "deploy": "gh-pages -d build"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6️⃣ Push the Project to GitHub
&lt;/h2&gt;

&lt;p&gt;Run the following commands to initialize and push your project to GitHub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
git add .
git commit -m "First commit"
git branch -M main
git remote add origin https://github.com/&amp;lt;your-github-username&amp;gt;/deploy-react-git.git
git push -u origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7️⃣ Deploy the App
&lt;/h2&gt;

&lt;p&gt;Run the deployment command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a &lt;code&gt;gh-pages&lt;/code&gt; branch.&lt;/li&gt;
&lt;li&gt;Build and deploy your project to GitHub Pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8️⃣ Enable GitHub Pages
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;code&gt;Repository Settings &amp;gt; Pages&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Under Branch, select &lt;code&gt;gh-pages&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Save&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the &lt;code&gt;gh-pages&lt;/code&gt; branch is selected by default, then leave it as it is.&lt;br&gt;
After a few minutes, your site will be live at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://&amp;lt;your-github-username&amp;gt;.github.io/deploy-react-git/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9️⃣ (Optional) Automate Future Deployments
&lt;/h2&gt;

&lt;p&gt;To update your project and redeploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m "Updated project"
git push origin main
npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures your site stays updated with the latest changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 Have Questions or Feedback?
&lt;/h2&gt;

&lt;p&gt;I'd love to hear from you! If you have any questions, need clarification, or just want to share your thoughts, drop a comment below.&lt;br&gt;
Your feedback will help to improve and create better tutorials for you. Let's keep the conversation going! 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  🎉 Support Me!
&lt;/h2&gt;

&lt;p&gt;If this guide was helpful, kindly consider supporting me by:&lt;br&gt;
✅ Linking &amp;amp; Following&lt;br&gt;
✅ Subscribing to the channel: &lt;a href="https://www.youtube.com/@halogenius-ideas" rel="noopener noreferrer"&gt;https://www.youtube.com/@halogenius-ideas&lt;/a&gt;&lt;br&gt;
✅ Sharing it with your friends&lt;br&gt;
Thank you! 🚀&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
