You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何高效将30个独立React项目批量推送至Github?

Efficiently Push 30 React Projects to GitHub as a Portfolio

Hey there! Great question—curating your React projects into a GitHub portfolio is a fantastic way to showcase your work, and while you do need separate GitHub repositories (these are the "folders" you’re thinking of) for each project, there are several tricks to automate the process so you don’t have to repeat the same steps 30 times. Here’s how to streamline it:

1. Batch Create Standard .gitignore Files

All React projects share nearly identical .gitignore needs (node_modules, build artifacts, env files, etc.), so you don’t need to write one from scratch for each project.

  • First, create a single, generic React .gitignore file in the parent folder that contains all 30 project directories. Include standard entries like node_modules/, build/, .env, .DS_Store, etc.
  • Then use a command-line one-liner to copy this file into every project folder:
    • Mac/Linux: Run this in the parent directory:
      find . -type d -maxdepth 1 -mindepth 1 -exec cp .gitignore {} \;
      
    • Windows (Command Prompt):
      for /d %i in (*) do copy .gitignore "%i\"
      
    • Windows (PowerShell):
      Get-ChildItem -Directory | ForEach-Object { Copy-Item .gitignore $_.FullName }
      

2. Automate Git Initialization & Remote Push with a Script

Instead of manually initializing each repo, committing files, and linking to GitHub, write a simple script to handle this in bulk. The easiest way is to use the GitHub CLI (gh) to create remote repos directly from the command line (no need to click around the GitHub website).

Step 1: Set Up GitHub CLI

  • Install gh (it’s free and official)
  • Run gh auth login to connect your GitHub account

Step 2: Run the Batch Script

Create a bash script (for Mac/Linux) or PowerShell script (for Windows) in your parent folder. Here’s a bash example:

#!/bin/bash

# Loop through every project directory in the parent folder
for project_dir in */; do
    # Remove the trailing slash from the directory name
    project_name=${project_dir%/}
    
    echo "Processing project: $project_name"
    
    # Navigate into the project folder
    cd "$project_dir"
    
    # Initialize local Git repo
    git init
    
    # Stage all files
    git add .
    
    # Make the initial commit
    git commit -m "Initial commit: $project_name (React portfolio project)"
    
    # Create a public GitHub repo and push the local code to it
    # Use --private instead of --public if you want repos to be private
    gh repo create "$project_name" --public --source . --push
    
    # Navigate back to the parent folder
    cd ..
done
  • Save this as push-projects.sh, make it executable with chmod +x push-projects.sh, then run it with ./push-projects.sh.
  • If you don’t want to use GitHub CLI, you’ll need to manually create all 30 repos on GitHub first, then replace the gh repo create line with:
    git remote add origin https://github.com/YourGitHubUsername/$project_name.git
    git push -u origin main
    

3. Create a "Portfolio Hub" Repo

To make it easy for recruiters or visitors to browse all your projects, create a single main repo (e.g., react-portfolio) that acts as a directory. In its README, list each project with:

  • A short description of what it does
  • Links to the project’s GitHub repo
  • Screenshots or demo links (if you’ve deployed them)
  • Key technologies used (e.g., React, Redux, Tailwind CSS)

This turns your scattered repos into a cohesive portfolio that’s easy to navigate.

Quick Tips

  • Don’t skip project READMEs: Each individual project should have its own README explaining how to run it, its features, and any challenges you solved. This shows attention to detail.
  • Test first: Run the script on 1-2 projects first to make sure it works as expected before processing all 30.
  • Avoid sensitive data: Double-check that your .gitignore includes files like .env that might have API keys or passwords.

内容的提问来源于stack exchange,提问作者user74843

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:06:44