Home » FAQ » General » What is the correct procedure for merging?

The correct procedure for merging (with a focus on Git and modern code platforms)

The correct procedure for merging is to synchronize with the target branch, update and test your feature branch, open a pull/merge request for review, resolve conflicts, ensure all checks pass, choose an appropriate merge strategy (merge commit, squash, or rebase), complete the merge, and then clean up the source branch. Below is a step-by-step guide that explains how to do this safely and consistently in Git, along with platform-specific notes for GitHub, GitLab, and Bitbucket. If you meant merging in a non-software context, see the section near the end for alternatives.

Why merging matters

Merging integrates changes from one line of development into another—most commonly from a feature branch into the main branch. Doing it well protects code quality, maintains a trustworthy history, and reduces production risk.

Pre-merge checklist

Before you begin, confirm these prerequisites to reduce conflicts and avoid breaking your build or deployment pipeline.

  • Confirm the target branch (usually main or a release branch) and ensure you have access and approvals.
  • Update your local repository: fetch latest and confirm you’re working off the newest main.
  • Run tests and linters locally; fix any failures.
  • Ensure commits are clean, scoped, and well-described (consider Conventional Commits).
  • Verify that secrets and large files are handled correctly (e.g., Git LFS where needed).
  • Check that CI/CD will run on your pull/merge request and that required checks are green.
  • Confirm branch protection or merge policies (reviews, signed commits, required checks).

If these items are in place, your merge is far more likely to be smooth, reviewable, and auditable.

Step-by-step merging with Git (CLI)

The following sequence covers a typical feature-into-main merge flow, showing both merge and rebase options. Use one approach consistently per team policy.

  1. Fetch and update your local main:

    git fetch origin

    git checkout main

    git pull --ff-only

  2. Update your feature branch:

    git checkout feature/my-change

  3. Bring main into your feature branch (choose one):

    – Merge: git merge main

    – Rebase: git rebase main

  4. Resolve any conflicts, run tests, and lint. If you rebased, update the remote safely:

    git push --force-with-lease

  5. Open a pull request (PR) or merge request (MR) to main. Link issues, add reviewers, and include a clear description.
  6. Ensure CI passes and address review feedback; keep the branch up to date (rebase or merge main again if needed).
  7. Complete the merge using the agreed strategy (merge commit, squash, or rebase-and-merge).
  8. Delete the source branch (locally and remotely) unless your policy requires keeping it:

    git branch -d feature/my-change

    git push origin --delete feature/my-change

This process creates a traceable, reviewed integration that is compatible with protected branches and modern CI/CD workflows.

Resolving conflicts safely

Conflicts arise when changes touch the same lines or adjacent areas. Handle them deliberately to avoid regressions.

  • Use a three-way merge tool to see base/current/incoming clearly.
  • Resolve conflicts file by file; run tests after each logical chunk.
  • Prefer the version that reflects current system behavior; re-apply necessary logic from both sides.
  • For binary or generated files, regenerate artifacts rather than hand-editing.
  • After resolving, mark as resolved and continue:

    – Merge flow: git add ., git commit

    – Rebase flow: git add ., git rebase --continue

  • If you get stuck: git merge --abort or git rebase --abort to reset the attempt.

Conflicts are normal; careful resolution, followed by tests, preserves correctness and team velocity.

Choosing the right merge strategy

Teams should standardize on a strategy that fits their history and release practices. Here are the main options and when to use them.

  • Merge commit: preserves full branch history; best for larger teams and when multiple commits matter. Default on many platforms.
  • Squash and merge: condenses a feature branch into a single commit; ideal for keeping main linear and concise.
  • Rebase and merge: reapplies commits onto main for a linear history; requires discipline and signed-off CI.
  • Fast-forward only: only allows merges if the target can move forward without a merge commit; common in trunk-based dev with frequent syncs.
  • No-ff merge (explicit merge commit): forces a merge commit even when FF is possible, aiding feature grouping.

Pick one per repository or per branch type and enforce it with branch protection to avoid accidental inconsistencies.

Merging via GitHub

GitHub provides PR workflows with protections and automation that streamline safe merges.

  • Open a PR to the protected branch (often main). Complete the PR template and link issues.
  • Ensure required status checks and reviews pass (Branch protection rules).
  • Use Update branch to bring main into your PR if it’s behind; organizations can enforce rebase or merge updates.
  • Choose a merge option: Merge commit, Squash and merge, or Rebase and merge (repo settings control availability).
  • Use Auto-merge to merge automatically when checks pass, or Merge queue to batch and serialize merges to reduce CI flakiness.
  • Optionally require signed commits, linear history, or CODEOWNERS approvals.

These controls reduce risk and maintain a consistent, auditable history while aligning with your team’s policy.

Merging via GitLab

GitLab’s Merge Requests integrate tightly with pipelines and approvals to gate merges on quality signals.

  • Create a Merge Request targeting main or a release branch; include a clear description and issue references.
  • Use Required approvals, code owners, and security scans as part of the MR pipeline.
  • Enable Pipelines must succeed to block merges on failing CI.
  • Select a strategy: Merge commit, Squash, Fast-forward only, or Semi-linear history (rebases before merging).
  • Use Merge trains or Merge Trains with Pipelines (akin to a queue) to reduce integration race conditions.

GitLab’s merge trains and approval gates help large teams land changes predictably without breaking main.

Merging via Bitbucket (Cloud and Server)

Bitbucket supports PR-based workflows with merge checks and default reviewers to standardize quality.

  • Open a Pull Request with a descriptive title and summary; add default or required reviewers.
  • Configure Merge checks (e.g., minimum approvals, no merge if build fails, no unresolved tasks).
  • Choose merge strategy per repo: Merge commit, Squash, or Fast-forward only.
  • Use Branch permissions to protect main and release branches.

These features ensure only reviewed, validated code lands in your primary branches.

Post-merge actions

After merging, a brief wrap-up keeps your repo and deployments healthy.

  • Confirm CI/CD on the target branch is green; monitor canary or production if auto-deploying.
  • Tag a release if appropriate; update changelogs or release notes.
  • Delete the merged branch to reduce clutter unless policy dictates otherwise.
  • If issues were linked, close them or move them to the next workflow state.
  • Communicate notable changes in team channels or documentation.

These steps complete the loop from change to value and keep your project organized.

Common pitfalls and how to avoid them

Avoid these frequent mistakes that can derail merges or pollute history.

  • Rebasing public branches without using --force-with-lease risks overwriting teammates’ work.
  • Skipping tests after conflict resolution invites regressions.
  • Mixing large refactors with functional changes makes reviews harder; split them.
  • Committing secrets or large binaries without LFS can break pipelines and security; scan before merging.
  • Ignoring platform policies (required checks, approvals) leads to blocked or reverted merges.

Consistent discipline and automation catch most of these issues early.

If you meant a different kind of merging

Outside of source control, “merging” often refers to combining data or documents, or even merging traffic. Here’s how to approach those succinctly.

  • Data/CSV/database merging: normalize schemas, define a source of truth, deduplicate with stable keys, validate with row counts and checksums, and version your transformations.
  • Document merging/redlining: track changes, accept/reject revisions in order, resolve conflicting edits, and export a clean final document.
  • Traffic lane merging: signal early, match speed to traffic, use the zipper merge (alternating vehicles) where lanes converge, and yield as required by local laws.

Each domain has its own norms and tools; pick procedures that emphasize clarity, safety, and auditability.

Summary

The correct procedure for merging is to keep your target branch current, update and test your feature branch, use a PR/MR with reviews and required checks, resolve conflicts carefully, select an appropriate merge strategy, complete the merge through your platform’s guarded workflow, and clean up afterward. Standardize this process across your team and enforce it with branch protections and CI to keep history clean and main stable.

T P Auto Repair

Serving San Diego since 1984, T P Auto Repair is an ASE-certified NAPA AutoCare Center and Star Smog Check Station. Known for honest service and quality repairs, we help drivers with everything from routine maintenance to advanced diagnostics.

Leave a Comment