Lesson 1 of 2 Source Control and Pipeline Triggers

Applying Version Control and Branching Strategies

Version control is the foundation of every automated pipeline because the repository is where changes begin and where the history of every release is kept. This lesson explains how Git organises change, compares the common branching strategies, and shows how branch and repository structure decide which pipelines run and which environments they update.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain the Git concepts that pipelines depend on: commits, branches, tags, merges and pull requests.
  • Compare trunk-based development, GitHub flow and Git flow, and identify the strengths of each.
  • Describe how branches and tags map to pipelines and application environments.
  • Identify repository practices that protect the main branch and keep secrets out of source control.

Git Concepts that Pipelines Depend On

Git is a distributed version control system. Each developer has a full copy of the repository, makes changes locally and pushes them to a shared remote repository hosted by a Git provider such as GitHub, GitLab or Bitbucket. Pipelines on AWS react to changes in that remote repository, so it is important to understand the objects Git creates.

Commit
A snapshot of the repository with a unique SHA identifier, an author and a message. A pipeline execution records the commit ID it built, which links every deployment to exact source.
Branch
A movable pointer to a commit. Developers create branches to work on changes in isolation; the main branch represents the integrated code.
Merge
Combines the history of one branch into another. A merge to main is the event that usually starts a release pipeline.
Pull request
A request to merge a branch, with review comments and status checks. Pull requests are also called merge requests in GitLab. Builds started by pull requests validate changes before they are merged.
Tag
A named, fixed pointer to a commit, typically a version such as v2.4.0. Tags are used to mark releases and can start release pipelines.

Because a commit ID is immutable, it is the most reliable identifier for what was built. Pipelines commonly pass the commit ID into build environment variables, image tags and deployment descriptions so that an operator can trace a running container back to the code that produced it.

Branching Strategies

A branching strategy defines how long branches live, where changes are integrated and how releases are cut. The strategy affects how many pipelines are needed and how often integration problems occur.

Trunk-based development

In trunk-based development, developers commit to the main branch (the trunk) directly or through very short-lived feature branches that are merged within a day or two. Incomplete features are hidden behind feature flags rather than kept on separate branches. There is one release pipeline that runs on every merge to main. This strategy suits continuous delivery and continuous deployment best, because the main branch is always integrated and releasable. AWS AppConfig feature flags, described in a later module, support this approach by separating deployment of code from release of a feature.

GitHub flow

GitHub flow is a lightweight variant: every change is developed on a feature branch, a pull request is opened, automated checks and reviews run, and the branch is merged to main, which is then deployed. It differs from strict trunk-based development mainly in requiring a pull request for every change. It is common for teams that deploy frequently from a single main branch.

Git flow

Git flow uses long-lived develop and main branches plus feature, release and hotfix branches. Features merge into develop; a release branch is cut from develop for stabilisation and then merged into main and tagged. Git flow suits products with scheduled, versioned releases, such as installable software, but it creates more merge work and longer feedback loops, and it maps less naturally to continuous deployment.

The table below summarises the three strategies.

StrategyLong-lived branchesTypical release triggerBest suited to
Trunk-based developmentMain onlyEvery merge to mainContinuous delivery or deployment of services
GitHub flowMain only, with short-lived feature branches and pull requestsMerge of a pull request to mainWeb services with frequent releases and mandatory review
Git flowMain and develop, plus release and hotfix branchesMerge of a release branch and a version tagScheduled, versioned product releases

Mapping Branches and Tags to Pipelines and Environments

Pipelines are integrated with application environments through the events that a repository emits. There are three common mapping patterns, and many organisations combine them.

  • One pipeline per long-lived branch. A pipeline that watches main deploys to production through staging; a second pipeline that watches develop deploys to a development environment. This is simple but duplicates pipeline definitions.
  • Pull request validation builds. A build runs for every pull request and reports a status back to the Git provider. Branch protection rules prevent merging until the status is successful. The build does not usually deploy, although some teams create a short-lived preview environment for each pull request and delete it when the request is closed.
  • Tag-based releases. A pipeline starts only when a tag that matches a pattern, such as v*, is pushed. Pipeline type V2 in CodePipeline supports trigger filters on Git tags, branches and file paths, so one pipeline can ignore ordinary commits and respond only to release tags.

File path filters are useful in a monorepo, where one repository holds several services. A pipeline for the orders service can include only changes under services/orders/**, so a change to another service does not start an unnecessary release.

The following diagram shows the mapping patterns side by side.

Three ways to map repository events to pipelines. A pipeline per long-lived branch: main deploys through staging to production and develop deploys to a development environment. Pull request validation: a build runs for each pull request and reports a status that branch protection requires before merging. Tag-based release: a V2 pipeline with a tag filter such as v* starts only for release tags. In a monorepo, file path filters start only the pipeline for the service that changed.
Trigger filters decide which events start which pipeline.

Protecting the Main Branch

Because the main branch is what gets deployed, Git providers offer branch protection settings that pipelines rely on. A protected branch can require a pull request for every change, a minimum number of approving reviews, successful status checks from a CI build, and a linear or signed commit history. These controls are configured in the Git provider, not in AWS, but the CI build that reports the status check is commonly an AWS CodeBuild project. CodeBuild reports build status back to GitHub, GitHub Enterprise Server, GitLab and Bitbucket when the project's source is configured to report build status.

Repositories should also contain a CODEOWNERS file or equivalent so that changes to sensitive paths, such as pipeline definitions or IAM policies in templates, require review by the owning team.

Keeping Secrets Out of Source Control

Secrets such as database passwords, API keys and signing keys must never be committed to a repository, even a private one. Git history is permanent: deleting the file in a later commit leaves the secret in earlier commits and in every clone. Instead, secrets are stored in AWS Secrets Manager or as SecureString parameters in AWS Systems Manager Parameter Store, and builds and applications retrieve them at run time using IAM permissions. If a secret is committed by mistake, the correct response is to rotate the secret immediately, because removing it from history does not undo the exposure. Pre-commit hooks and secret scanning in the build provide an additional safeguard. The handling of secrets in builds is covered in the AWS CodeBuild module.

Plaintext secrets

A common exam distractor stores credentials in environment variables in plain text in a CodeBuild project or in a configuration file in the repository. Both expose the value to anyone who can read the project or the repository. The correct pattern references Secrets Manager or Parameter Store.

Scenario questions

Protect the repository

Exam skills 1.1.2 · 1.1.4

Practise branch protection and secret handling for repositories.

Log in to try this activity Interactive activities are free with an account.
Worked example

A Monorepo with Several Services

A company keeps three microservices and their CloudFormation templates in one GitHub repository. Each service has its own team and release cadence. Every commit currently starts all three pipelines, which wastes build minutes and occasionally redeploys services that did not change.

The company converts the three pipelines to pipeline type V2 and adds a push trigger to each, with a branch filter of main and a file path filter for that service's directory. Changes to services/payments/** now start only the payments pipeline. A shared library directory is included in all three filters, because a change to it affects every service. Pull requests are validated by a CodeBuild project with a webhook filter on pull request events, and branch protection requires that build to succeed before merging.

Check yourself

A team uses trunk-based development and wants to merge incomplete features to main without exposing them to users. What technique supports this?

Show answer

Feature flags. The code is deployed but the feature remains switched off until the flag is enabled, for example with an AWS AppConfig feature flag, so deployment and release are separated.

Exam Tips

Remember for the exam

  • Trunk-based development and short-lived branches suit continuous delivery and deployment; long-lived branches delay integration and increase merge conflicts.
  • CodePipeline V2 triggers can filter on branches, Git tags and file paths, which avoids unnecessary executions in monorepos and lets one pipeline respond only to release tags.
  • If a secret is committed to a repository, rotate it; deleting the file does not remove it from Git history.
  • Pull request builds validate changes before merge and report status back to the Git provider, where branch protection can require a successful build.