<?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: Tousif Izaz</title>
    <description>The latest articles on DEV Community by Tousif Izaz (@tousifizaz).</description>
    <link>https://dev.to/tousifizaz</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%2F3554946%2Fe1bfecb6-f59e-4e7f-9fb9-f44f67f70343.jpeg</url>
      <title>DEV Community: Tousif Izaz</title>
      <link>https://dev.to/tousifizaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tousifizaz"/>
    <language>en</language>
    <item>
      <title>Setting up Automatic Deployment from one repository to another</title>
      <dc:creator>Tousif Izaz</dc:creator>
      <pubDate>Thu, 09 Oct 2025 02:57:12 +0000</pubDate>
      <link>https://dev.to/tousifizaz/setting-up-automatic-deployment-from-one-repository-to-another-33ce</link>
      <guid>https://dev.to/tousifizaz/setting-up-automatic-deployment-from-one-repository-to-another-33ce</guid>
      <description>&lt;p&gt;I recently wanted to host my React portfolio on GitHub Pages, but with a twist. Most tutorials show you how to deploy to &lt;strong&gt;[username.github.io/repository-name]&lt;/strong&gt;, which is straightforward. However, I wanted my portfolio to live at the &lt;strong&gt;root&lt;/strong&gt; domain: &lt;strong&gt;username.github.io&lt;/strong&gt;.&lt;br&gt;
But, I didn't want my GitHub Pages repository cluttered with React source code, node_modules, and development files. I wanted clean separation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One repository for my React source code (development, version control, collaboration)&lt;/li&gt;
&lt;li&gt;Another repository (username.github.io) with only the production build&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Manually building and pushing every time I made changes? Not ideal. There had to be a better way.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cross-Repository GitHub Actions
&lt;/h2&gt;

&lt;p&gt;After some tinkering, I discovered GitHub Actions could automate deployments &lt;strong&gt;between repositories&lt;/strong&gt;. Here's what I learned.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding GitHub Pages Root Domain Deployment
&lt;/h2&gt;

&lt;p&gt;Option A: Put React code in username.github.io&lt;br&gt;
❌ Messy: Source code mixed with builds&lt;br&gt;
❌ Unprofessional: Shows development artifacts&lt;/p&gt;

&lt;p&gt;Option B: Build locally, push to username.github.io&lt;br&gt;
❌ Manual process every deployment&lt;br&gt;
❌ Error-prone: Forget to build? Push wrong files?&lt;br&gt;
❌ Not scalable: No CI/CD pipeline&lt;/p&gt;

&lt;p&gt;Option C: Separate repos + GitHub Actions&lt;br&gt;
✅ Clean separation of concerns&lt;br&gt;
✅ Automated builds and deployments&lt;br&gt;
✅ Professional CI/CD workflow&lt;/p&gt;
&lt;h2&gt;
  
  
  The Solution: Two-Repository Architecture
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Repository 1: my-portfolio (Private/Public)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;React source code&lt;/li&gt;
&lt;li&gt;Development dependencies&lt;/li&gt;
&lt;li&gt;GitHub Actions workflow&lt;/li&gt;
&lt;li&gt;Version control for features&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Repository 2: username.github.io (Public)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Only production build files&lt;/li&gt;
&lt;li&gt;Automatically updated by CI/CD&lt;/li&gt;
&lt;li&gt;Serves the live website&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1: Setting Up the Workflow File
&lt;/h2&gt;

&lt;p&gt;In my React repository, I created .github/workflows/deploy.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Deploy to GitHub Pages

on:
  push:
    branches:
      - main  # Triggers on every push to main
  workflow_dispatch:  # Allows manual deployment

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout source repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test -- --watchAll=false --passWithNoTests
        continue-on-error: false

      - name: Build React app
        run: npm run build
        env:
          CI: true

      - name: Verify build output
        run: |
          echo "Build completed successfully"
          ls -la ./build
          du -sh ./build

      - name: Deploy to GitHub Pages repository
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
          external_repository: username/username.github.io
          publish_branch: main #branch name of repo u want to deploy to
          publish_dir: ./build #directory of the action
          user_name: 'github-actions[bot]'
          user_email: 'github-actions[bot]@users.noreply.github.com'
          commit_message: 'Deploy from ${{ github.repository }}@${{ github.sha }}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Authentication Setup
&lt;/h2&gt;

&lt;p&gt;GitHub Actions needs permission to push to another repository. Here's what I learned about authentication options:&lt;/p&gt;

&lt;h3&gt;
  
  
  Option A: Personal Access Token (What I Used)
&lt;/h3&gt;

&lt;p&gt;Creating the token:&lt;/p&gt;

&lt;p&gt;GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)&lt;br&gt;
Generate new token (classic)&lt;br&gt;
Name it descriptively: "Portfolio Deploy to GitHub Pages"&lt;br&gt;
Expiration: Choose based on security needs&lt;br&gt;
Required scopes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;repo&lt;/strong&gt; - Full control of repositories&lt;br&gt;
&lt;strong&gt;workflow&lt;/strong&gt; - Update GitHub Action workflows&lt;/p&gt;

&lt;p&gt;Adding to repository secrets:&lt;/p&gt;

&lt;p&gt;Go to React repository → Settings → Secrets and variables → Actions&lt;br&gt;
New repository secret&lt;br&gt;
Name: PAGES_DEPLOY_TOKEN&lt;br&gt;
Value: Paste the token&lt;br&gt;
Add secret&lt;/p&gt;
&lt;h4&gt;
  
  
  Option B: Deploy Keys (More Secure Alternative)
&lt;/h4&gt;

&lt;p&gt;I also explored deploy keys, which are SSH-based and repository-specific:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Generate SSH key pair
ssh-keygen -t ed25519 -C "deploy-key-pages" -f deploy_key -N ""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Then:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add deploy_key.pub to username.github.io → Settings → Deploy keys (with write access)&lt;br&gt;
Add deploy_key (private) to React repo → Settings → Secrets as PAGES_DEPLOY_KEY&lt;/p&gt;

&lt;p&gt;Update workflow to use deploy_key: ${{ secrets.PAGES_DEPLOY_KEY }} instead of personal_token.&lt;/p&gt;
&lt;h4&gt;
  
  
  Why I chose Personal Access Token:
&lt;/h4&gt;

&lt;p&gt;Simpler for a single-user portfolio. Deploy keys are better for team projects.&lt;/p&gt;
&lt;h4&gt;
  
  
  Configuring the Build
&lt;/h4&gt;

&lt;p&gt;Important customizations I had to make:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yaml# Node version matching my local environment
node-version: '18'  # Check with: node --version

# Build output directory
publish_dir: ./build  # React uses 'build', Vite uses 'dist'

# Package manager
run: npm ci  # Or 'yarn install --frozen-lockfile' for Yarn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pro tip: Always verify your build directory locally:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
ls -la  # Check if 'build' or 'dist' folder was created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4: Testing the Workflow&lt;br&gt;
First deployment:&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 .github/workflows/deploy.yml
git commit -m "Add automated deployment workflow"
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I monitored it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;React repository → Actions tab&lt;/li&gt;
&lt;li&gt;Watched the "Deploy to GitHub Pages" workflow&lt;/li&gt;
&lt;li&gt;Each step showed real-time logs&lt;/li&gt;
&lt;li&gt;Green checkmarks = success! &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Within 5 minutes, username.github.io received the build files and my portfolio was live!&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Works: The Complete Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Developer pushes code
        ↓
GitHub Actions triggers in React repo
        ↓
1. Checkout source code
2. Install dependencies
3. Run tests
4. Build React app (npm run build)
5. Generate ./build folder
        ↓
Workflow authenticates with token
        ↓
Push build files to username.github.io
        ↓
GitHub Pages auto-deploys
        ↓
Site live at username.github.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Troubleshooting Issues I Encountered
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Issue 1: Build Fails in CI but Works Locally
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Different Node versions&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: Match Node version in workflow to local:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node --version  # Check local version
# Update workflow: node-version: '18'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Issue 2: 404 on GitHub Pages
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;: Routing issues with React Router&lt;br&gt;
&lt;strong&gt;Solution&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure your homepage for the react is set correctly. &lt;/li&gt;
&lt;li&gt;Add 404.html that redirects to index.html or use hash routing:
&lt;code&gt;&amp;lt;BrowserRouter basename="/"&amp;gt;&lt;/code&gt; // For username.github.io&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/en/actions" rel="noopener noreferrer"&gt;GitHub Actions Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/peaceiris/actions-gh-pages" rel="noopener noreferrer"&gt;peaceiris/actions-gh-pages&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.github.com/en/pages" rel="noopener noreferrer"&gt;GitHub Pages Documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>cicd</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
