Here are common Git and GitHub commands you'll use when working on a React project, broken
down by workflow stage:
Initial Setup
bash
CopyEdit
# Clone a repository
git clone https://github.com/username/repo-name.git
# Initialize Git in your React project (if not already a repo)
git init
# Add a remote repository
git remote add origin https://github.com/username/repo-name.git
Typical Workflow
Stage, Commit, and Push Changes
bash
CopyEdit
# Check status of your files
git status
# Stage all changes
git add .
# Or stage specific files
git add src/App.js
# Commit with a message
git commit -m "Add feature X"
# Push changes to remote (main branch)
git push origin main
Branching
bash
CopyEdit
# Create a new branch
git checkout -b feature/my-new-feature
# Switch to an existing branch
git checkout develop
# Push a new branch to GitHub
git push -u origin feature/my-new-feature
Pull and Merge
bash
CopyEdit
# Pull latest changes from main
git pull origin main
# Merge another branch into current one
git merge feature/my-new-feature
Cleanup
bash
CopyEdit
# Delete a branch locally
git branch -d feature/my-old-branch
# Delete a branch remotely
git push origin --delete feature/my-old-branch
React-Specific (Local Dev)
bash
CopyEdit
# Start React development server
npm start
# Install dependencies
npm install
# Build for production
npm run build