Q18Branching
What is a detached HEAD?
Detached HEAD means `HEAD` points directly to a commit rather than a branch name. It is useful for inspecting old revisions, but new commits can…
Answer
Detached HEAD means `HEAD` points directly to a commit rather than a branch name. It is useful for inspecting old revisions, but new commits can become hard to find unless a branch is created.
Syntax
git switch --detach <commit>
git switch -c investigate-old-bug
Example
Inspect an old release and create a branch if you need to keep a fix.
Code example
git switch --detach v1.4.0
# if editing and committing:
git switch -c hotfix/investigation
Diagram
HEAD → commit (not branch)
Key Points
- Create a branch to preserve new commits
Q20Branch Integration
What is a fast-forward merge?
A fast-forward occurs when the target branch is an ancestor of the source branch, so Git can move the target reference forward without creating a…
Answer
A fast-forward occurs when the target branch is an ancestor of the source branch, so Git can move the target reference forward without creating a merge commit.
Syntax
git merge --ff-only feature/docs
Example
Use `--ff-only` when policy requires avoiding accidental merge commits.
Code example
git switch main
git merge --ff-only origin/main
Diagram
main A—B; feature A—B—C → main moves to C
Key Points
- No divergence
- no merge commit
Q21Branch Integration
What is a three-way merge?
When branches diverge, Git uses their common ancestor and both branch tips to calculate a merge result. Conflicting edits to the same region may…
Answer
When branches diverge, Git uses their common ancestor and both branch tips to calculate a merge result. Conflicting edits to the same region may require manual resolution.
Syntax
git merge feature/payment
Example
Integrate independent work on the main branch and payment branch.
Code example
git switch main
git merge feature/payment
# resolve conflicts, then:
git add src/payment.ts
git commit
Diagram
Base + ours + theirs → merge result
Key Points
- The merge base is central to conflict analysis
Q23Branch Integration
What is Git rebase?
Rebase replays commits onto a new base, producing a more linear history. Replayed commits have new IDs. Rebase local unpublished work freely, but…
Answer
Rebase replays commits onto a new base, producing a more linear history. Replayed commits have new IDs. Rebase local unpublished work freely, but coordinate before rewriting commits others rely on.
Syntax
git switch feature/cart
git rebase main
Example
Update a feature branch with current main before opening or refreshing a pull request.
Code example
git fetch origin
git switch feature/cart
git rebase origin/main
Diagram
Feature commits replayed on latest main
Key Points
- Rebase changes commit identity
- conflicts may recur per commit
Q24Branch Integration
Merge vs rebase: when should you use each?
Merge preserves the actual integration topology and is suitable for shared history. Rebase creates a linear sequence and is useful for cleaning u…
Answer
Merge preserves the actual integration topology and is suitable for shared history. Rebase creates a linear sequence and is useful for cleaning up private work. Avoid rewriting shared/public history unless the team explicitly coordinates it.
Syntax
git merge main
git rebase main
Example
Rebase a private feature branch before review; merge the reviewed change according to repository policy.
Code example
git fetch origin
git rebase origin/main
# resolve, test, then push if allowed
Diagram
Merge: join histories; Rebase: replay commits
Key Points
- Choose based on collaboration and project policy
Q25Branch Integration
What is cherry-pick?
`git cherry-pick` applies the changes introduced by selected commit(s) onto the current branch, creating new commit IDs. It is useful for targete…
Answer
`git cherry-pick` applies the changes introduced by selected commit(s) onto the current branch, creating new commit IDs. It is useful for targeted fixes but can duplicate changes across branches.
Syntax
git cherry-pick <commit>
Example
Backport a one-line production fix to a maintained release branch.
Code example
git switch release/1.x
git cherry-pick a1b2c3d
Diagram
Commit from branch A → apply patch on branch B
Key Points
- Resolve conflicts
- document backports
- avoid unnecessary duplication
Q27Undo & Recovery
How do you undo the last commit safely?
The right command depends on whether the commit is shared and whether you want to keep its changes. `git revert` creates a new inverse commit; `g…
Answer
The right command depends on whether the commit is shared and whether you want to keep its changes. `git revert` creates a new inverse commit; `git reset` moves the current branch reference and may rewrite local history.
Syntax
git revert <commit>
git reset --soft HEAD~1
Example
Undo a pushed change using revert so teammates' history remains intact.
Code example
git revert a1b2c3d
# for a private local commit only:
git reset --soft HEAD~1
Diagram
Bad commit → inverse commit (shared history)
Key Points
- Prefer revert for published commits
Q28Undo & Recovery
What is the difference between reset, revert, and restore?
`reset` moves the current branch/HEAD and can alter the index or working tree; `revert` records a new commit that reverses an earlier commit; `re…
Answer
`reset` moves the current branch/HEAD and can alter the index or working tree; `revert` records a new commit that reverses an earlier commit; `restore` replaces file content in the working tree or index.
Syntax
git reset --soft HEAD~1
git revert <commit>
git restore <path>
Example
Choose the command based on whether history is shared and which state you want to change.
Code example
git restore --staged src/app.ts
git restore --source=HEAD -- src/app.ts
Diagram
Reset: move pointer; Revert: add inverse commit; Restore: restore file state
Key Points
- Understand destructive effects before running reset/restore
Q34Pull Requests
How should code review be performed?
Review correctness, design, readability, security, performance, tests, and maintainability. Ask specific, respectful questions and distinguish bl…
Answer
Review correctness, design, readability, security, performance, tests, and maintainability. Ask specific, respectful questions and distinguish blockers from suggestions. Authors should respond to each thread and keep the diff reviewable.
Syntax
Review checklist: correctness → tests → security → maintainability
Example
A reviewer asks for a test covering an empty input rather than simply requesting a rewrite.
Code example
# Useful local review commands:
git diff main...HEAD
git diff --check
git status --short
Diagram
Author diff → reviewer feedback → revision → approval
Key Points
- Review behavior and risk, not personal style
Q35Repository Governance
What are branch protection rules?
Branch protection rules or rulesets can require pull requests, approvals, status checks, signed commits, linear history, or restrict force pushes…
Answer
Branch protection rules or rulesets can require pull requests, approvals, status checks, signed commits, linear history, or restrict force pushes/deletions. They help prevent unreviewed or failing code from reaching important branches.
Syntax
Require PR + 1 approval + required CI checks
Example
Protect `main` so only reviewed and passing changes can merge.
Code example
# Example policy (configure in GitHub settings):
# main requires pull request
# required status check: test
# disallow force pushes
Diagram
Developer → PR → required checks/approval → protected main
Key Points
- Align rules with team size and deployment risk
Q36Repository Governance
What are CODEOWNERS files?
A `CODEOWNERS` file maps paths to owners. GitHub can automatically request reviews from those owners, helping route changes to people responsible…
Answer
A `CODEOWNERS` file maps paths to owners. GitHub can automatically request reviews from those owners, helping route changes to people responsible for sensitive or specialized areas.
Syntax
/infra/ @platform-team
/src/payments/ @payments-team
Example
Require payment-service owners to review changes under the payment directory.
Code example
# .github/CODEOWNERS
/src/payments/ @org/payments-team
/.github/workflows/ @org/platform-team
Diagram
Changed path → CODEOWNERS match → review request
Key Points
- Ensure owners have repository access and maintain the file
Q39CI/CD Fundamentals
Continuous integration vs continuous delivery vs continuous deployment?
Continuous integration frequently integrates changes and validates them automatically. Continuous delivery ensures a release can be deployed with…
Answer
Continuous integration frequently integrates changes and validates them automatically. Continuous delivery ensures a release can be deployed with a deliberate approval. Continuous deployment automatically releases every qualifying change to production.
Syntax
CI: build/test
CDelivery: deployable release + approval
CDeployment: automatic production release
Example
A regulated team may use continuous delivery with a manual production approval.
Code example
# pipeline stages
lint_and_test -> build -> staging -> approval -> production
Diagram
CI → ready artifact; delivery adds release decision; deployment automates production
Key Points
- The terms differ mainly in the production release decision
Q40GitHub Actions
What is a workflow, job, step, and runner in GitHub Actions?
A workflow is a YAML automation triggered by events. A workflow contains jobs; jobs run on runners and contain steps. Steps run shell commands or…
Answer
A workflow is a YAML automation triggered by events. A workflow contains jobs; jobs run on runners and contain steps. Steps run shell commands or actions and usually execute sequentially within a job.
Syntax
workflow → jobs → steps
runs-on: ubuntu-latest
Example
Use separate jobs for tests and packaging, with a dependency between them.
Code example
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm ci
- run: npm test
build:
needs: test
runs-on: ubuntu-latest
steps:
- run: npm run build
Diagram
Event → workflow → job runner → ordered steps
Key Points
- Jobs may run in parallel unless connected with `needs`
Q42GitHub Actions
How do you cache dependencies in GitHub Actions?
Caching reuses dependency downloads or build data between runs. Use a cache key that changes when lockfiles or relevant tool versions change; cac…
Answer
Caching reuses dependency downloads or build data between runs. Use a cache key that changes when lockfiles or relevant tool versions change; caching should improve speed, not replace reproducible installation.
Syntax
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
Example
Cache npm's download cache while continuing to install from the lockfile.
Code example
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
Diagram
Lockfile hash → cache lookup → install missing dependencies
Key Points
- Use lockfiles and deterministic installs
- don't cache secrets
Q43Pipeline Security
How do you store secrets in GitHub Actions?
Store credentials in GitHub Actions secrets or environment secrets, scope access narrowly, and avoid printing them. Prefer short-lived federated…
Answer
Store credentials in GitHub Actions secrets or environment secrets, scope access narrowly, and avoid printing them. Prefer short-lived federated credentials such as OIDC when supported instead of long-lived cloud keys.
Syntax
${{ secrets.DEPLOY_TOKEN }}
Example
Use an environment-scoped secret for staging deployment and require approval for production.
Code example
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: ./scripts/deploy.sh
Diagram
Secret store → scoped workflow/job → deployment command
Key Points
- Never hard-code secrets
- masking is not a substitute for safe logging
Q45GitHub Actions
How do you use a matrix build?
A matrix strategy runs the same job across combinations such as operating systems, runtime versions, or dependency versions. Use it for compatibi…
Answer
A matrix strategy runs the same job across combinations such as operating systems, runtime versions, or dependency versions. Use it for compatibility coverage while controlling total execution cost.
Syntax
strategy:
matrix:
node: [20, 22]
Example
Test a library against two supported Node.js versions.
Code example
strategy:
matrix:
node-version: [20, 22]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
Diagram
One job definition × matrix values → multiple job runs
Key Points
- Use `fail-fast` and `max-parallel` intentionally
Q46GitHub Actions
How do you pass artifacts between workflow jobs?
Jobs usually run on separate runner instances. Upload build outputs as artifacts in one job and download them in another, or publish immutable ar…
Answer
Jobs usually run on separate runner instances. Upload build outputs as artifacts in one job and download them in another, or publish immutable artifacts to a registry. Avoid rebuilding different bytes for production than were tested.
Syntax
upload-artifact → download-artifact
Example
Build a distributable once, then deploy the same package to staging and production.
Code example
- uses: actions/upload-artifact@v4
with:
name: web-build
path: dist/
# downstream job:
- uses: actions/download-artifact@v4
with:
name: web-build
path: dist/
Diagram
Build job → artifact store → deploy job
Key Points
- Treat artifacts as versioned release inputs
Q48Automated Testing
What is the testing pyramid?
The testing pyramid recommends many fast unit tests, fewer integration tests, and a smaller number of end-to-end tests. The mix depends on the sy…
Answer
The testing pyramid recommends many fast unit tests, fewer integration tests, and a smaller number of end-to-end tests. The mix depends on the system, but feedback should be fast and failures diagnosable.
Syntax
Unit tests > Integration tests > End-to-end tests
Example
Validate business logic with unit tests, database boundaries with integration tests, and a few critical user journeys end to end.
Code example
# Example test commands
npm run test:unit
npm run test:integration
npm run test:e2e
Diagram
Many unit tests → fewer integration tests → few E2E tests
Key Points
- Avoid relying solely on slow, brittle end-to-end tests
Q51Automated Testing
What is code coverage, and what are its limits?
Coverage measures which code was executed by tests, commonly line, branch, or function coverage. High coverage does not prove assertions are corr…
Answer
Coverage measures which code was executed by tests, commonly line, branch, or function coverage. High coverage does not prove assertions are correct or edge cases are tested; use it as a signal, not the goal.
Syntax
npm test -- --coverage
Example
Add tests for error branches, not only lines that make the coverage percentage rise.
Code example
# Example Jest configuration output
# Statements: 86%
# Branches: 72%
# Functions: 90%
# Lines: 87%
Diagram
Tests execute paths → coverage report → review uncovered risk
Key Points
- Branch coverage often reveals untested decision outcomes
Q53Build & Artifacts
What is an artifact in a CI/CD pipeline?
An artifact is a versioned output such as a compiled binary, container image, package, or static site bundle. Promote the same artifact through e…
Answer
An artifact is a versioned output such as a compiled binary, container image, package, or static site bundle. Promote the same artifact through environments to improve traceability and avoid environment-specific rebuild differences.
Syntax
source → build artifact → test → promote
Example
Build a container once and promote its digest from staging to production.
Code example
docker build -t registry.example.com/app:${GITHUB_SHA} .
docker push registry.example.com/app:${GITHUB_SHA}
Diagram
Commit → immutable artifact → staging → production
Key Points
- Record source revision, dependencies, and artifact digest
Q56Deployment Strategies
What is a rolling deployment?
A rolling deployment gradually replaces instances running the old version with new instances. It reduces the need for a full outage, but the appl…
Answer
A rolling deployment gradually replaces instances running the old version with new instances. It reduces the need for a full outage, but the application must tolerate mixed versions during the rollout.
Syntax
old instances → replace a subset → replace remaining instances
Example
Update a web service across a pool while health checks remove unhealthy instances.
Code example
# Kubernetes-style example
kubectl rollout status deployment/web
kubectl set image deployment/web web=example/web:v2
Diagram
v1 fleet → mixed v1/v2 → v2 fleet
Key Points
- Ensure readiness probes and backward compatibility
Q57Deployment Strategies
What is a blue-green deployment?
Blue-green deployment maintains two production-like environments. The new version is deployed and validated in the inactive environment, then tra…
Answer
Blue-green deployment maintains two production-like environments. The new version is deployed and validated in the inactive environment, then traffic switches to it. Rollback can switch traffic back if the previous environment remains healthy.
Syntax
Blue active → deploy Green → validate → switch traffic
Example
Deploy v2 to green, run smoke tests, then switch the load balancer.
Code example
# Conceptual commands
./deploy.sh green v2
./smoke-test.sh green
./switch-traffic.sh green
Diagram
Blue (live) + Green (candidate) → traffic switch
Key Points
- Costs more resources
- database compatibility still matters
Q59Deployment Strategies
What is a feature flag, and how does it help delivery?
A feature flag separates deploying code from enabling behavior. It can support gradual rollout, experiments, and rapid disablement, but stale fla…
Answer
A feature flag separates deploying code from enabling behavior. It can support gradual rollout, experiments, and rapid disablement, but stale flags create complexity and need ownership and removal plans.
Syntax
if featureFlags.newCheckout:
showNewCheckout()
Example
Deploy a new checkout path disabled, enable it for internal users, then gradually expand.
Code example
const enabled = await flags.isEnabled("new-checkout", user.id);
if (enabled) {
return renderNewCheckout();
}
return renderLegacyCheckout();
Diagram
Deploy code → flag off → targeted enablement → full rollout
Key Points
- Flags are not authorization controls
- evaluate sensitive access separately
Q61Infrastructure & Delivery
What is Infrastructure as Code (IaC)?
IaC defines infrastructure in version-controlled configuration so environments can be reviewed, reproduced, tested, and changed through controlle…
Answer
IaC defines infrastructure in version-controlled configuration so environments can be reviewed, reproduced, tested, and changed through controlled workflows. Plans should be reviewed before applying destructive changes.
Syntax
terraform fmt
terraform validate
terraform plan
Example
Run a plan on a pull request and apply only after an authorized merge or approval.
Code example
terraform init -input=false
terraform fmt -check
terraform validate
terraform plan -out=tfplan
Diagram
Infrastructure code → plan/review → approved apply
Key Points
- Protect state files and credentials
- review drift and destructive plans
Q64Supply Chain Security
What is dependency scanning?
Dependency scanning identifies known vulnerabilities in packages and libraries. Combine lockfiles, automated alerts, risk-based update policies,…
Answer
Dependency scanning identifies known vulnerabilities in packages and libraries. Combine lockfiles, automated alerts, risk-based update policies, and CI checks while evaluating whether a finding is exploitable in the actual application.
Syntax
npm audit
# or ecosystem-specific scanner
Example
Run dependency review on pull requests and block high-risk newly introduced vulnerabilities according to policy.
Code example
npm ci
npm audit --audit-level=high
Diagram
Lockfile/dependencies → vulnerability database → report/policy
Key Points
- Review false positives and transitive dependency paths
Q66Supply Chain Security
What is an SBOM?
A Software Bill of Materials lists software components and useful metadata such as versions and relationships. It supports vulnerability response…
Answer
A Software Bill of Materials lists software components and useful metadata such as versions and relationships. It supports vulnerability response, inventory, and compliance, but its quality depends on accurate generation and maintenance.
Syntax
generate → validate → publish SBOM
Example
Attach an SBOM to a versioned release artifact for downstream consumers.
Code example
syft registry:example.com/app:1.2.0 -o spdx-json > sbom.spdx.json
Diagram
Artifact → component inventory → consumers/security response
Key Points
- Generate it for the artifact actually released
Q67Supply Chain Security
How do you scan for secrets in a repository?
Secret scanning searches code and repository history for credential patterns or known tokens. Preventive hooks and CI checks help, but if a secre…
Answer
Secret scanning searches code and repository history for credential patterns or known tokens. Preventive hooks and CI checks help, but if a secret is exposed, revoke or rotate it immediately; deleting the line is not enough.
Syntax
pre-commit scan + CI secret scan
Example
A detected cloud key triggers revocation, rotation, and an audit of its use.
Code example
# Example with an installed scanner
gitleaks detect --source . --redact
Diagram
Commit → secret scanner → pass/fail and remediation
Key Points
- Treat exposed credentials as compromised
Q71Configuration Management
How do you manage environment variables across stages?
Keep configuration separate from application code, use environment-specific settings for non-secret values, and managed secret stores for credent…
Answer
Keep configuration separate from application code, use environment-specific settings for non-secret values, and managed secret stores for credentials. Validate required settings at startup and avoid baking production secrets into build artifacts.
Syntax
APP_ENV=staging
LOG_LEVEL=info
Example
Deploy the same artifact to staging and production with different runtime endpoints and credentials.
Code example
APP_ENV=staging
API_BASE_URL=https://api-staging.example.com
# credentials injected separately
Diagram
Same artifact + stage configuration → runtime
Key Points
- Avoid environment-specific rebuilds and secret leakage
Q72Pipeline Design
What are quality gates in a pipeline?
Quality gates are conditions that must pass before the pipeline proceeds, such as tests, linting, coverage thresholds, vulnerability checks, appr…
Answer
Quality gates are conditions that must pass before the pipeline proceeds, such as tests, linting, coverage thresholds, vulnerability checks, approvals, or performance budgets. Gates should focus on actionable risks.
Syntax
lint AND tests AND security scan → eligible
Example
Block deployment if tests fail or a critical policy-defined vulnerability is introduced.
Code example
if tests_pass and scan_pass and approval_granted:
deploy()
else:
stop_pipeline()
Diagram
Checks → gate decision → deploy or stop
Key Points
- Avoid noisy gates that teams routinely bypass
Q78GitHub Actions
How do you handle concurrency and cancel outdated runs?
Concurrency groups can ensure only one run for a given group is active, and `cancel-in-progress` can stop superseded runs. Choose groups carefull…
Answer
Concurrency groups can ensure only one run for a given group is active, and `cancel-in-progress` can stop superseded runs. Choose groups carefully so a newer commit does not cancel a deployment that must finish safely.
Syntax
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
Example
Cancel old PR validation when a newer commit is pushed to the same PR branch.
Code example
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Diagram
New commit → same group → old validation cancelled
Key Points
- Use separate policies for deployment jobs and critical migrations
Q79Pipeline Design
How do you deploy only from the main branch?
Restrict deployment jobs with branch conditions and environment protection. Branch checks alone are not sufficient for every security boundary; a…
Answer
Restrict deployment jobs with branch conditions and environment protection. Branch checks alone are not sufficient for every security boundary; also control who can change workflow files and who can approve production.
Syntax
if: github.ref == 'refs/heads/main'
Example
Allow production deployment only after a successful workflow on main.
Code example
if: github.ref == 'refs/heads/main'
steps:
- run: ./deploy-production.sh
Diagram
Validated main commit → protected environment → deploy
Key Points
- Combine conditions with environment rules and least privilege
Q80Releases & Tags
What is a release pipeline?
A release pipeline packages a known revision, runs release checks, creates version metadata and notes, publishes artifacts, and deploys or promot…
Answer
A release pipeline packages a known revision, runs release checks, creates version metadata and notes, publishes artifacts, and deploys or promotes them according to policy. It should preserve traceability from source commit to running version.
Syntax
tag → validate → package → publish → deploy
Example
Creating tag `v2.3.0` starts release packaging and publishes an immutable artifact.
Code example
on:
push:
tags: ["v*.*.*"]
jobs:
release:
runs-on: ubuntu-latest
steps:
- run: echo "Package and publish release"
Diagram
Version tag → build → artifact → release notes/deployment
Key Points
- Verify the tag points to an approved commit