Typical branching model and pull requests
A common branching workflow looks like this:- The production-ready line of development lives on the
main(historicallymaster) branch. Code onmainis what gets deployed to production. - New work happens on feature branches such as
feature/Aorfeature/B. Feature branches isolate changes until they are ready. - When a feature is ready, a developer pushes commits to the feature branch and opens a pull request (PR) to merge into
main. - Reviewers inspect the PR and CI pipelines typically run automatically to validate the changes before merge.
Why CI is necessary
Without Continuous Integration, teams commonly face:- Delayed testing: Tests run late, often after multiple changes are merged, making root-cause analysis harder.
- Inefficient deployments: Manual steps across environments (dev, staging, prod) increase the chance of configuration drift and human error.
- Lower quality assurance: Heavy reliance on manual verification causes bottlenecks and inconsistent coverage.
A typical CI flow (feature branch → PR → merge)
A typical CI workflow for a single feature might look like:- Developer 1 creates
feature/A, implements changes, and pushes commits. - A pull request is opened to merge
feature/Aintomain. - A CI pipeline is triggered for the PR. Common stages:
- Unit tests
- Dependency and license scanning
- Build artifact creation
- Static analysis and vulnerability scanning
- Optional: container image build and push to a registry
- CI systems often run tests against a simulated merge commit (feature branch merged into
main) to catch integration issues early. - If tests fail, the developer updates
feature/Aand pushes new commits. The CI pipeline re-runs until it passes. - Once CI succeeds, reviewers approve the PR and it is merged into
main. - A
mainpipeline runs after merge. This pipeline may:- Produce canonical release artifacts
- Run additional integration or end-to-end tests
- Prepare deployment packages for CD
main serves complementary purposes: PR pipelines validate proposed changes in isolation (or via merge simulation), while main pipelines validate the actual post-merge state and produce the artifacts used for deployment.
Parallel work and integration
- Multiple developers can work in parallel on different feature branches (
feature/A,feature/B). - Each feature branch triggers its own PR pipeline.
- After both branches are merged,
mainnow contains changes from both features. ThemainCI pipeline ensures the combined changes build and pass tests together.
Continuous Integration is primarily about frequent automated builds and tests that validate integrations early and often, reducing the chance that defects reach production.
CD: Continuous Deployment vs Continuous Delivery
CD refers to the pipeline that takes validated CI artifacts through environments and into production. There are two common variants:| CD Mode | Description | Typical use case |
|---|---|---|
| Continuous Deployment | Successful CI on main automatically deploys artifacts to production with no human intervention. | High-release-frequency teams with strong automated testing and observability. |
| Continuous Delivery | CI produces deployable artifacts, but a manual approval (a gate) is required before production. | Teams needing compliance checks, coordinated releases, or extra human validation. |
- After a successful PR CI run, optionally deploy the feature branch or the merge result to a staging/dev environment.
- Run integration, smoke, or end-to-end tests in that environment.
- If tests pass, merge the PR. The
mainCI verifies the merged state and triggers the CD pipeline. - The CD pipeline deploys to staging and either:
- Automatically promotes to production (Continuous Deployment), or
- Waits for manual approval before promoting to production (Continuous Delivery).
Recommended CI pipeline stages (example)
- checkout code
- install dependencies / cache dependencies
- run unit tests (fast feedback)
- run linting / static analysis
- run integration/e2e tests (can be staged)
- build and tag artifacts (e.g., Docker images)
- push artifacts to registry / store release artifacts
- run vulnerability scans and policy checks
- deploy to staging (optional) and run smoke tests
Best practices and tips
- Keep PRs small and focused—smaller changes reduce review time and make CI faster.
- Run fast feedback (unit tests, linters) first, then long-running tests (integration, e2e).
- Use branch protections to require passing CI and at least one review before merging
main. - Make pipeline logs and failure messages clear to speed up debugging.
- Automate rollbacks and canary deployments in production to reduce blast radius.
- Cache dependencies and split workloads to optimize CI runtime and cost.
Summary
- CI automates building and testing on feature branches and PRs to detect integration issues early.
- CI runs both on PRs (to validate proposed changes) and on
mainafter merge (to validate the canonical state and produce artifacts). - CD moves validated artifacts through environments (staging → production). It can be fully automated (Continuous Deployment) or require a manual approval before production (Continuous Delivery).
- Together, CI and CD help teams deliver higher-quality software faster and with less operational risk.