Appearance
Git Workflow, Branches and Versions
187. What is the difference between Git merge, rebase, and squash merge?
The short answer
All three bring a branch's changes into another branch, but they leave different history. A merge keeps both lines of history and joins them with a merge commit. A rebase replays your commits one by one on top of the target, so history becomes a straight line, but the commits get new IDs. A squash merge combines all of the branch's commits into one single new commit on the target.
Merge (git merge feature):
- Keeps every commit exactly as it was, plus a merge commit with two parents.
- History shows the true story: when the branch split off and when it came back.
- With many branches, the history graph gets tangled and hard to read.
Rebase (git rebase main, run on the feature branch):
- Takes each of your commits and re-applies it on top of the latest main, creating new commits with new IDs.
- History becomes a straight line, easy to read and easy to search with
git bisect, a tool that finds which commit introduced a bug. - The golden rule: never rebase commits others have already pulled. Rewriting shared history breaks everyone else's copy.
Squash merge, the "Squash and merge" button on most platforms:
- Combines all of the branch's commits into one new commit on main.
- Main gets one tidy commit per pull request, often titled with the pull request's name.
- The branch's individual "fix typo" and "try again" commits disappear from main's history.
Which to use. Many teams squash-merge pull requests into main, for a clean history where each commit is one reviewed change that is easy to revert. Developers often rebase their own branch on main before merging, to stay up to date without merge commits.
188. How do trunk-based development and GitFlow differ?
The short answer
In trunk-based development, everyone integrates into one main branch, the trunk, through very short-lived branches, usually merged within a day or two, and releases come straight from the trunk. Unfinished features hide behind feature flags. GitFlow uses several long-lived branches, such as develop, release and hotfix branches alongside main, with work moving between them through planned merges. GitFlow suits scheduled, versioned releases. Trunk-based development suits continuous delivery.
| Trunk-based development | GitFlow | |
|---|---|---|
| Long-lived branches | Only main | main and develop, plus release branches |
| Branch lifetime | Hours to two days | Days to weeks |
| Unfinished work | Hidden behind feature flags | Kept on feature branches |
| Releases | From main, often | Through a release branch, on a schedule |
| Merge pain | Small and frequent | Large and occasional |
| Fits | Continuous delivery, web services | Versioned products, scheduled releases |
GitFlow, described by Vincent Driessen in 2010, gives each kind of work its own branch:
developcollects finished features.feature/*branches split offdevelopfor each feature.release/*branches split offdevelopto stabilise a version.mainholds only released versions, each tagged.hotfix/*branches split offmainfor urgent fixes and are merged back into bothmainanddevelop.
In 2020, Driessen himself added a note to his article saying that for software delivered continuously, such as web apps, a simpler workflow is usually a better fit.
Trunk-based development keeps one line. Developers create a branch, open a pull request, and merge it the same day or the next. Releases are tags or short release branches cut from main. Because everything integrates constantly, the problems GitFlow's merges were designed to manage simply do not build up.
189. Which branching strategy would you choose for a team deploying multiple times per day, and why?
The short answer
Trunk-based development: short-lived branches merged into main within a day, every merge checked and deployable, and unfinished features hidden behind feature flags. Deploying many times a day only works when every change is small and main is always releasable. Long-lived branches work against both, because they make changes large and integration late.
Why it fits frequent deployment:
- Small changes are safe changes. A pull request with 80 changed lines is easy to review, easy to check, and easy to roll back. A month-long branch with 4,000 lines is none of those.
- Main is always releasable. Every merge goes through the pipeline, so main can be deployed at any moment, which continuous delivery requires (question 172).
- No merge days. Conflicts are found when they are a few lines, not a few files.
- Fast feedback. Production shows within hours whether a change works.
How it works in practice: a common, simple version is often called GitHub flow:
- Create a branch from main.
- Commit, push, and open a pull request.
- The pipeline checks it, and a teammate reviews it.
- Merge into main.
- Main deploys automatically, to staging and then production.
What it needs to work:
- Feature flags, so half-built features can be merged without being visible (question 285).
- Fast, trustworthy checks, ideally under ten minutes.
- Good review habits, with small pull requests reviewed promptly.
- Fast rollback, because mistakes will reach production and must be cheap to undo.
When I would not choose it: software released in versions that customers install, such as mobile apps or on-premises products, often needs release branches to support several versions at once (question 194).
190. How do you manage hotfixes while keeping development, staging, and production in sync?
The short answer
Fix it in main first, through a normal but fast pull request, and deploy it forward through the same pipeline, so the fix can never be lost. If main contains other changes that cannot go to production yet, branch from the release tag that is in production, fix it there, deploy that, and immediately bring the same fix back into main. Either way, the hotfix goes through the required checks, and every environment ends up containing it.
Case 1: main is releasable, the normal case with trunk-based development.
- Open a pull request with the fix against main.
- Review it quickly. The checks still run.
- Merge. The pipeline builds and deploys it to staging, then to production, as usual, perhaps with a faster approval.
Every environment gets the fix in the normal order, and nothing can drift.
Case 2: main holds changes that are not ready for production.
- Create
hotfix/1.4.1from the tagv1.4.0, which is exactly what production runs. - Fix the bug there, through a pull request with the normal checks.
- Build, tag
v1.4.1, and deploy through staging to production. - Bring the same fix into main straight away, by merging or cherry-picking it. A cherry-pick copies one commit onto another branch.
The classic mistake is forgetting step 4. The next normal release, built from main, does not contain the fix, and the bug comes back. This is called a regression. A rule that hotfix pull requests are not complete until the main pull request is merged prevents it.
Keep the checks. Urgency is exactly when mistakes happen. A hotfix can have a faster review and approval, but it should skip as few checks as possible (question 298).
191. How do semantic versioning, release tags, and commit SHAs fit into a release process?
The short answer
A commit SHA identifies the exact source code. A release tag, such as v1.4.2, is a name pinned to one commit, marking it as a release. Semantic versioning gives that name a meaning: the first number changes for breaking changes, the second for new features, and the third for fixes. The image built from that commit carries both the SHA and the version as tags, and its digest identifies the exact bytes, so you can always trace a version back to its code.
Semantic versioning, or SemVer, uses MAJOR.MINOR.PATCH:
| Part | Increase when | Example |
|---|---|---|
| MAJOR | You make a change that breaks users | 1.4.2 to 2.0.0 |
| MINOR | You add something new that does not break anything | 1.4.2 to 1.5.0 |
| PATCH | You fix a bug without changing behaviour otherwise | 1.4.2 to 1.4.3 |
It also allows pre-release labels, such as 1.5.0-rc.1 for a release candidate.
How the identifiers line up:
v1.4.2 → commit 3f9c2ab8... → image tags 1.4.2 and 3f9c2ab → digest sha256:41c9...
version exact source human-friendly names exact bytes- The commit SHA is a hash of the commit, so it identifies the exact source and history. Short forms such as
3f9c2abare fine for humans. - The release tag is created in Git:
git tag -a v1.4.2 -m "Release 1.4.2", and pushing it usually starts the release pipeline (question 184). - The image is tagged with both, so it can be found by version or by commit.
- The digest is what deployments use, because only it is guaranteed never to move (question 35).
For internal services that deploy many times a day, semantic versions matter less. Many teams just use the commit SHA, or a date-based version. For libraries and public APIs, semantic versioning matters a lot, because it tells users whether upgrading is safe.
192. How do you prevent a pipeline from deploying an unreviewed or unapproved commit?
The short answer
Make every route to production depend on reviewed code. Protect main so code can only arrive through approved pull requests. Only allow production deployments from main, in the pipeline's environment settings. Only build release artifacts after merge. Give the production deploy identity permissions that only work from main. Finally, have the cluster verify each image's provenance, so an image built from anything other than reviewed main code is rejected.
Each layer closes a different gap:
- Branch protection on main. No direct pushes, required reviews from code owners, required checks, rules that apply to administrators too (question 186).
- Deploy only from main. Deployment environments in GitHub Actions, GitLab and Azure Pipelines can be restricted to certain branches. A workflow run from a feature branch simply cannot use the production environment.
- Production approval, if your process requires it, on the environment itself, so it cannot be skipped by editing the pipeline file (question 257).
- Credentials that only work from main. With OIDC, the cloud role used for production deploys can require that the token comes from the main branch, or from the production environment (question 269). Even if someone edits a workflow on a branch to deploy, the cloud refuses the token.
- Build release images only after merge, so every release image comes from reviewed code (question 185).
- Verify at the cluster. An admission policy checks that the image was signed by the release workflow on main (question 147). An image built anywhere else is rejected.
- No manual side doors. Nobody has
kubectl applyrights in production for routine work. Changes go through GitOps, and break-glass access is audited (question 271).
Why so many layers? Each one alone can be bypassed: a mis-set branch rule, an over-powerful token, a person with direct cluster access. Together, an unreviewed commit would have to get past all of them.
193. What is a monorepo, and how can a pipeline avoid rebuilding every service when only one service changes?
The short answer
A monorepo is one repository holding many services and libraries. To avoid rebuilding everything, the pipeline works out which projects a change affects, and builds and checks only those. The simple way is path filters: run a service's job only when files in its folder change. The thorough way uses a build tool that knows how projects depend on each other, so a change to a shared library also rebuilds every service that uses it.
A monorepo layout:
text
shop/
services/checkout-api/
services/catalog-api/
services/web/
libs/money/ used by checkout-api and catalog-api
libs/ui-kit/ used by webOption 1: path filters, simple and built into most CI systems:
yaml
on:
pull_request:
paths:
- 'services/checkout-api/**'
- 'libs/money/**'This workflow runs only when files under those folders change. The catch is that you must keep the list of dependencies up to date by hand. Forget that checkout-api uses libs/money, and a broken change to the library slips through.
Option 2: a dependency-aware build tool. Tools such as Nx, Turborepo, Bazel and Gradle read how projects depend on each other and calculate which are "affected" by a change:
bash
npx nx affected -t build lint --base=origin/main --head=HEADThis compares the change with main, finds the changed projects plus everything that depends on them, and runs build and lint only for those. A change to libs/money rebuilds money, checkout-api and catalog-api, but not web.
Option 3: remote caching. These tools can also store each project's build results in a shared cache, keyed by the hash of its inputs. If a project's inputs did not change, its result is downloaded instead of rebuilt.
Details to get right:
- Compare with the right base: the point where the branch split from main, not just the last commit.
- Watch shared files. A change to the root lock file or the shared pipeline file may affect everything, and should rebuild everything.
- Images per service. Each service gets its own image and its own deploy, so one service's release never redeploys the others (question 438).
194. How should feature branches, release branches, and environment branches be used or avoided?
The short answer
Feature branches are fine when they are short-lived, merged within a day or two. Release branches are useful when you must stabilise or support a version separately, such as for mobile or installed software, as long as fixes flow back to main. Environment branches, a dev, staging and prod branch with code merged between them, are best avoided: they drift apart, they cause conflicts, they rebuild code per environment, and nobody can easily tell what is in production.
Feature branches:
- Use them for every change, through a pull request.
- Keep them short. A branch that lives for weeks is the integration problem continuous integration exists to prevent (question 171).
- Use feature flags for big features, so the branch can merge before the feature is finished.
Release branches:
- Useful when one version must be stabilised while main moves on, or when several versions are supported at once, such as
release/2.3andrelease/2.4of a product customers install. - Cut from main. Only fixes go in.
- Fixes are made on main and cherry-picked into the release branch, or made on the branch and merged back to main at once (question 190).
Environment branches, and why to avoid them:
The pattern: merge dev into staging to test, then staging into prod to release, and each branch deploys to its environment.
- Rebuilds per environment. Each branch builds its own artifact, so production runs something never tested (question 134).
- Drift. Hotfixes made on
prodand experiments left ondevpull the branches apart. Merges between them start to conflict. - Unclear state. "What is in production?" becomes a Git archaeology exercise.
The better alternative: one main branch, one artifact per change, promoted between environments. The configuration for each environment lives in its own folder, such as deploy/staging/ and deploy/prod/, and promotion is a change to that folder (question 133).
195. How do you handle a merge conflict or failed integration build late in a release cycle?
The short answer
First protect the release. Either fix it forward if the fix is small and obvious, or revert the change that caused it, so main and the release are green again. A feature that is not ready can be switched off behind a flag or moved to the next release. Tell everyone affected what is happening. Afterwards, look at why integration happened so late, because that is the real problem to fix.
In the moment, pick the safest option:
- Fix forward, if the problem is small, well understood and fixable in minutes. For example, a conflict in one file, or a failing check with an obvious cause.
- Revert, if the fix is not obvious. Undo the change that broke the build, so main is green again, then fix it calmly on a branch. A revert is not a failure. It is the fastest way back to a releasable state.
- Switch it off, if the change is behind a feature flag. The code can stay, and the feature stays hidden.
- Move the feature to the next release, if it is not ready. A late, rushed merge of a large change is one of the most common causes of release-day incidents.
What not to do: force-merge with failing checks "to make the date", or merge a large conflict resolution without review and checks. Both turn a delayed release into a broken one.
Communicate. The release owner, the team and anyone waiting for the release need to know: what broke, what you are doing, and whether the date moves.
Then fix the cause. Late conflicts and late integration failures almost always mean changes stayed apart too long: long-lived branches, big-bang merges, or a "code freeze" that let work pile up. The lasting fix is integrating continuously, in small changes, behind flags (question 189).
196. How do you make pipeline runs traceable to the source commit, reviewer, artifact, and deployment?
The short answer
Carry identifiers forward at every step and record the links. The image gets the commit SHA as a tag and in its labels. The build records a signed provenance statement linking the image digest to the commit and the pipeline run. The pull request records who reviewed and approved it. Each deployment records which digest went where, when, and who approved it. And the running app reports its own commit, so you can trace backwards from a live pod too.
What to record at each step:
- Pull request: the platform keeps who opened it, who reviewed it, the discussion and the checks. Squash-merge commits usually include the pull request number in the message.
- Commit: the SHA identifies the exact source.
- Pipeline run: the run's ID and link. Most CI systems expose the commit SHA as a variable, such as
GITHUB_SHA. - Image: tags with the commit SHA, OCI labels for the source and revision (question 220), and a signed provenance statement linking digest, commit and run (question 146).
- Deployment: the environment, the digest, the time, who or what approved it. In GitOps, this is the commit in the configuration repository that changed the digest, plus the GitOps tool's sync history.
- Running workload: an annotation on the Deployment with the commit, and a
/versionendpoint in the app that returns its commit and build time.
Why it pays off. During an incident, "what changed?" is the first question. With this chain, you answer it in seconds: production's pods run digest X, built from commit Y, from pull request Z, deployed at 14:02. Auditors ask the same question in a slower way, and get the same answer.
197. What is the difference between a pipeline trigger and a pipeline dependency?
The short answer
A trigger is an event that starts a pipeline: a push, a pull request, a schedule, a tag, or another pipeline finishing. A dependency is an ordering rule between pieces of work: this job, stage or pipeline may only run after that one has succeeded, and may use what it produced. Triggers decide when work starts. Dependencies decide in what order it runs once started.
Triggers answer "when does this run?":
yaml
on:
push:
branches: [main]
schedule:
- cron: '0 3 * * 1'This workflow starts on every push to main, and every Monday at 03:00.
Dependencies answer "what must finish first?":
yaml
jobs:
build:
runs-on: ubuntu-latest
steps: [ { run: make build } ]
scan:
needs: build # (1)
runs-on: ubuntu-latest
steps: [ { run: make scan } ]
deploy-dev:
needs: [build, scan] # (2)
runs-on: ubuntu-latest
steps: [ { run: make deploy-dev } ]scanwaits forbuildto succeed.deploy-devwaits for both. If either fails, it does not run.
Where the two meet: one pipeline starting another. This can be a trigger or a dependency, depending on the tool:
- In GitHub Actions,
on: workflow_runis a trigger: when the "ci" workflow completes, this "deploy" workflow starts. - In GitLab, a
trigger:job starts a downstream pipeline, and the parent can wait for its result, which acts like a dependency. - In Jenkins, the
build job:step starts another job, and can wait for it.
Why the distinction matters: a common bug is a deployment pipeline that is triggered by "CI finished", but does not check that CI succeeded. It then deploys after a failed build. A real dependency, or a trigger with an explicit success condition, prevents that.
198. What are pipeline variables, parameters, and environment variables, and how do they differ?
The short answer
Pipeline variables are named values the pipeline system stores and substitutes into the pipeline, such as a region name or a registry address, and some can be marked secret. Parameters are inputs given when a pipeline or a template is started, often typed and checked, such as "which environment do you want to deploy to?". Environment variables are the ordinary operating system variables that the commands inside a step can read. The pipeline usually turns its variables into environment variables for each step.
| Pipeline variable | Parameter | Environment variable | |
|---|---|---|---|
| Defined by | Pipeline file or settings | The pipeline or template's inputs | The OS process of each step |
| Set when | Before or during the run | When the pipeline or template is started | When each step's process starts |
| Typed and checked | Usually not | Often, such as a list of allowed choices | No, always text |
| Can be secret | Yes | Usually no | Yes, if fed from a secret |
| Read by | The pipeline system | The pipeline system | Your commands and scripts |
In GitHub Actions:
yaml
on:
workflow_dispatch:
inputs:
environment: # (1)
type: choice
options: [staging, production]
env:
REGISTRY: myacr.azurecr.io # (2)
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- run: ./deploy.sh "$REGISTRY" "$TARGET" # (3)
env:
TARGET: ${{ inputs.environment }}
REGION: ${{ vars.AZURE_REGION }} # (4)- A parameter: someone starting the workflow by hand must pick
stagingorproduction. Anything else is rejected. - A value set as an environment variable for every step.
- The script reads both as normal environment variables. Wrapping them in double quotes in the shell is a good habit, so values with spaces stay intact.
- A repository variable, a pipeline variable stored in the repository's settings rather than in the file, exposed to this step as an environment variable.
In Azure Pipelines the difference is even sharper. Parameters are filled in when the pipeline is compiled, before it runs, so they can change the pipeline's structure, for example by adding or removing whole stages. Variables are substituted at run time. That is why templates use parameters for structure and variables for values.
One safety point: pipeline expressions are pasted into the script before it runs. If a value comes from an untrusted source, such as a pull request title, pasting it straight into a run: line can let someone inject commands. Passing it through an environment variable, as in step 3, avoids that (question 270).
480. What are Conventional Commits, and how can they automate version numbers and changelogs?
The short answer
Conventional Commits is a simple rule for writing commit messages: start with a type, such as feat or fix, optionally a scope in brackets, then a short description, like feat(checkout): add saved cards. Because the messages are structured, tools can read them to decide the next version number automatically: a fix raises the patch number, a feat raises the minor number, and a breaking change raises the major number. The same tools write the changelog from the messages.
The format:
text
type(scope): short description
optional longer explanation
optional footer, such as BREAKING CHANGE: ...| Type | Meaning | Version effect |
|---|---|---|
fix | A bug fix | Patch: 1.4.2 to 1.4.3 |
feat | A new feature | Minor: 1.4.2 to 1.5.0 |
feat! or a BREAKING CHANGE: footer | A breaking change | Major: 1.4.2 to 2.0.0 |
docs, chore, ci, refactor, perf, build | Other changes | Usually none |
Examples:
text
fix(cart): keep discount when quantity changes
feat(checkout): support saved cards
feat(api)!: remove the v1 orders endpointWhat tools do with it. Tools such as semantic-release and release-please read every commit since the last release, work out the next version, create the Git tag, write the changelog, and publish the release, all from the pipeline. Nobody argues about version numbers, and nobody forgets to update the changelog.
Enforcing it. A check called commitlint can run in CI and fail pull requests whose commit messages, or squash-merge titles, do not follow the format.
Why interviewers ask: it shows you know how release automation decides versions, and that commit messages can be a reliable source of release information rather than noise.