What is the difference between merge commit, squash, and rebase merging?
CI/CD & GitOps · Intermediate level
Answer
A merge commit preserves full branch history with a merge node. Squash combines the PR into one commit for a clean main history. Rebase replays commits on top of the target branch for linear history. I choose based on audit needs and team history policy.
Technical explanation
Use commands that preserve team auditability on shared branches; rewrite only local or explicitly coordinated history.
Always run the relevant test suite after conflict resolution or cherry-picking because code may compile but behavior can change.
GitHub delivery controls combine repository settings, branch protection, required status checks, environments, CODEOWNERS, and workflow permissions.
Use least-privilege permissions for the GITHUB_TOKEN and prefer OIDC federation over long-lived cloud access keys.
Separate trusted and untrusted workflow contexts, especially pull_request from forks, and avoid exposing secrets to unreviewed code.
Make merge policy explicit: linear history, squash, merge commits, signed commits, or code-owner approvals should match audit and release requirements.
Hands-on example
1. Implement the control for: What is the difference between merge commit, squash, and rebase merging in a GitHub repository that contains a simple service and.github/workflows/ci.yml.
2. Create a workflow with on: [pull_request], jobs: build, test, scan; set permissions: contents: read by default and grant write only to jobs that truly need it.
3. Add branch protection on main requiring the CI workflow, at least one approval, CODEOWNERS review for protected paths, conversation resolution, and no direct pushes.
4. Use environments for staging/prod with required reviewers and environment secrets; prefer OIDC cloud login over storing AWS/Azure/GCP access keys.
5. Validate by opening a PR that fails one required check and confirm GitHub blocks merge until the check passes and required reviewers approve.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More CI/CD & GitOps interview questions
- What is a branch protection rule, and what would you enforce on main?
- What is a pull request review workflow, and what gates would you require?
- How do you store and use secrets in GitHub Actions?
- What are required status checks, and how do they protect main?
- What is the difference between a GitHub-hosted and a self-hosted runner?
- Explain a typical Git branching strategy (trunk-based, Git flow, GitHub flow).
- What is a GitHub Actions workflow, job, step, and runner?
- What is the difference between trunk-based development and Git flow?