1. Simple Projects / Personal Repos
- Just use
main(ormaster) as your default branch. - Push code directly there.
- Ideal for solo projects, experiments, or small utilities where you donβt need complex environments.
2. Team Projects / Professional Setup
Use multiple branches to separate environments:
-
main(ormaster): always stable, production-ready code. -
develop(orqa): integration branch where features are merged and tested. -
staging: optional, mirrors production but used for pre-release testing. -
feature/*: short-lived branches for individual features or bug fixes. -
hotfix/*: for urgent fixes applied directly to production.
Note: This way, you can test in QA, validate in staging, and only merge into main when the code is truly production-ready.
3. GitFlow Model (Popular in Enterprises)
-
mainβ production releases. -
developβ ongoing development. -
feature/*,release/*,hotfix/*β specialized branches for workflow control.
π Workflow Steps
1. Clone and Setup
git clone <repo-url>
cd <repo-name>
git checkout -b develop
2. Create Feature Branch
git checkout develop
git checkout -b feature/login-auth
3. Work and Commit
git add .
git commit -m "Add login authentication"
4. Push Feature Branch
git push origin feature/login-auth
5. Merge to Develop (QA)
git checkout develop
git merge feature/login-auth
git push origin develop
6. Promote to Staging
git checkout staging
git merge develop
git push origin staging
7. Release to Production
git checkout main
git merge staging
git push origin main
π Notes
- Always keep main clean and stable.
- Use Pull Requests (PRs) for merging β this ensures code review.
- Delete feature branches after merging to keep repo tidy.
- Hotfixes go directly into main and then back-merge into develop
βοΈ GitHub Actions CI/CD Pipeline
Yaml
name: CI/CD Pipeline
on:
push:
branches:
- develop
- staging
- main
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
deploy:
needs: build-test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Deploy to QA (Develop branch)
if: github.ref == 'refs/heads/develop'
run: echo "Deploying to QA environment..."
# Replace with actual deploy script, e.g.:
# run: ./scripts/deploy-qa.sh
- name: Deploy to Staging
if: github.ref == 'refs/heads/staging'
run: echo "Deploying to Staging environment..."
# run: ./scripts/deploy-staging.sh
- name: Deploy to Production
if: github.ref == 'refs/heads/main'
run: echo "Deploying to Production..."
# run: ./scripts/deploy-prod.sh
π How It Works
- Push to
developβ runs tests, then deploys to QA. - Push to
stagingβ runs tests, then deploys to Staging. - Push to
mainβ runs tests, then deploys to Production. - Each environment can have its own deployment script (
deploy-qa.sh,deploy-staging.sh,deploy-prod.sh).
π οΈ Next Steps
- Create deployment scripts for each environment (can be SSH, Docker, Kubernetes, or cloud CLI).
- Add environment secrets in GitHub (
Settings β Secrets and variables β Actions). - Example:
QA_SERVER,STAGING_SERVER,PROD_SERVER. - Replace the
echolines with real deployment commands.
Top comments (0)