Master GitHub deployments with our step-by-step guide. Learn to set up a repo, configure GitHub Actions, and trigger deploys automatically or via API.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Open or create a GitHub repository
Before you can trigger any deployment, you need a GitHub repository containing your project.
https://github.com/new
to create a new repository.git clone https://github.com/your-username/your-repo.git
cd your-repo
Step 2: Initialize a local project and commit changes
If you’re starting from scratch, initialize a Git repo, add code, and push to GitHub.
git init
echo "# MyProject" > README.md
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/your-username/your-repo.git
git push -u origin main
Step 3: Enable GitHub Actions for your repository
GitHub Actions provides CI/CD workflows. To deploy automatically, you’ll create a workflow file.
.github/workflows/
in your repo.
Step 4: Create a deployment workflow file
Inside .github/workflows/
, create a file named deploy.yml
.
name: Deploy Application
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Deploy to server
run: |
echo "Deploying to production..."
# insert your deploy commands here
Step 5: Commit and push the workflow
git add .github/workflows/deploy.yml
git commit -m "Add deployment workflow"
git push origin main
Step 6: Automatic deployment on push
With the above configuration, every push to the main
branch triggers the deploy job.
echo "console.log('hello')" >> index.js
git add index.js
git commit -m "Trigger deployment"
git push origin main
Step 7: Manual deployment trigger
You can trigger the workflow manually via the Actions tab or via GitHub REST API.
Deploy Application
and click Run workflow.
Step 8: Trigger deployment via REST API
Use GitHub’s REST API to dispatch the workflow programmatically.
curl -X POST \\
-H "Accept: application/vnd.github.v3+json" \\
-H "Authorization: token YOUR_PERSONAL_ACCESS\_TOKEN" \\
https://api.github.com/repos/your-username/your-repo/actions/workflows/deploy.yml/dispatches \\
-d '{"ref":"main"}'
YOUR_PERSONAL_ACCESS\_TOKEN
with a token having repo and workflow scopes.
Step 9: Verify your deployment
After triggering, check the workflow logs and your production endpoint.
Step 10: Advanced trigger options
You can extend triggers in deploy.yml
:
schedule
for cron jobs:on:
schedule:
- cron: '0 0 _ _ \*' # midnight UTC daily
pull\_request
to deploy preview builds:on:
pull\_request:
types: [opened, synchronize]
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.