Git Workflows
GitHub Flow (Simple)
Best for teams deploying frequently:
main ──●──●──●──●──●──●──●──
\ /
feature ●──●──●
- Create branch from
main - Make commits
- Open Pull Request
- Review and discuss
- Merge to
main - Deploy
Git Flow (Complex)
Best for scheduled releases:
main ──●─────────────────●── (releases)
\ /
release ●──●──●──●──●
\ /
develop ──●──●──●──●──●──●──
\ /
feature ●──●
Branches: main, develop, feature/*, release/*, hotfix/*
GitHub Actions
GitHub Actions automates workflows triggered by repository events.
Core Concepts
| Concept | Description |
|---|---|
| Workflow | YAML file in .github/workflows/ |
| Event | Trigger (push, PR, schedule) |
| Job | Set of steps running on a runner |
| Step | Individual task (action or command) |
| Runner | VM that executes jobs |
Your First Workflow
Create .github/workflows/ci.yml:
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest
- name: Run linter
run: flake8 .Multi-Job Pipeline
name: Build and Deploy
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npm test
build:
needs: test # Runs after test succeeds
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/download-artifact@v4
with:
name: build-output
- run: echo "Deploying to production..."Secrets and Variables
Store sensitive values in GitHub Settings → Secrets:
steps:
- name: Deploy
run: |
echo "Deploying..."
curl -X POST ${{ secrets.DEPLOY_URL }} \
-H "Authorization: Bearer ${{ secrets.DEPLOY_TOKEN }}"
env:
NODE_ENV: productionMatrix Strategy
Test across multiple versions:
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pytestDocker in GitHub Actions
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: username/app:latestSummary
- GitHub Flow: simple branch → PR → merge → deploy
- Git Flow: structured with develop, release, and hotfix branches
- GitHub Actions workflows live in
.github/workflows/*.yml on:defines triggers;jobs:defines what runsneeds:creates job dependencies;if:adds conditions- Secrets store sensitive values securely
- Matrix strategy tests across multiple configurations
Module Complete
You now understand Git version control and GitHub collaboration — from basic commits to automated CI/CD pipelines. These skills are foundational for every DevOps workflow.