
Editorial illustration: resolving a patch branch into a shared staging integration branch through a temporary intermediary branch.
A Git merge conflict is not Git telling you that your codebase is ruined. It is Git pausing to say that two branches changed the same lines in a file and it refuses to guess which version should survive.
Where teams get into trouble is where they fix it. Resolving a conflict directly on a shared staging branch—especially when QA testers, clients, or CI pipelines are actively using that branch—turns a routine merge into a live hazard. A much calmer approach is to spin up a temporary intermediary branch from the latest destination, merge the source branch there, resolve and test in isolation, and open a clean pull request back to the destination.
In the workflow below, we will use patch/payment-gateway-v4 as the source branch and env/staging-integration-core as the protected destination.
Why an intermediary branch beats fixing in place
A shared destination branch represents a live integration state. If you check it out and start editing conflict markers directly, you create a moving target: someone else might push while you are mid-edit, or a half-resolved commit could trigger a broken staging build before anyone reviews your choices.
An intermediary branch like chore/merge-patch-gateway-to-staging gives you a sandbox. Your destination branch stays untouched while you investigate, and the resulting pull request clearly isolates the conflict-resolution diff so reviewers can see what you decided without wading through unrelated staging commits.
One mental trap to watch out for: in this reverse-merge setup, HEAD (ours) is the intermediary branch forked from env/staging-integration-core, while theirs is the incoming patch/payment-gateway-v4 branch. Never rely on editor buttons like “Accept Current” or “Accept Incoming” blindly—always judge by what the code needs to do.
Prepare a clean workspace and sync remotes
Before touching any branch, make sure your working tree is clean:
git status
If you have half-finished work lying around, commit it to its own branch, stash it with a descriptive message (git stash push -m "wip: invoice layout"), or open a separate git worktree. Git’s merge documentation explicitly warns that uncommitted edits can prevent git merge --abort from cleanly restoring your starting state if things go wrong.
Next, fetch the latest remote references without altering your local files, switch to the destination branch, and fast-forward it:
git fetch origin
git switch env/staging-integration-core
git pull --ff-only origin env/staging-integration-core
Using --ff-only is a safety net. If your local env/staging-integration-core has diverged from origin, Git stops immediately instead of creating an accidental local merge commit. Check git log --oneline --decorate -5 to confirm you are sitting on the exact commit you expect.
Create the temporary branch and run the merge
Fork a short-lived branch from that updated destination:
git switch -c chore/merge-patch-gateway-to-staging
git merge origin/patch/payment-gateway-v4
Name the branch so it makes sense six months from now in git log—include the source and target or a ticket ID rather than something vague like fix-conflict.
If Git merges cleanly, still inspect the diff before celebrating. If it pauses with conflicts, use the terminal as your source of truth rather than relying on open editor tabs:
git status
git diff --name-only --diff-filter=U
The second command lists only the files that are still unmerged.
Read the conflict markers in context
Inside a conflicted file, you will see blocks like this:
<<<<<<< HEAD
current destination version
=======
incoming source version
>>>>>>> origin/patch/payment-gateway-v4
Read the whole function or config object, not just the five lines between the markers. Ask what the combined file is supposed to do once both branches’ work is present.
For example, suppose config-env.js has a staging callback URL on env/staging-integration-core, while patch/payment-gateway-v4 added a new FPX/gateway timeout and webhook signature header. Accepting HEAD drops the new timeout; accepting incoming might accidentally overwrite the staging endpoint with a sandbox default. The right answer is usually to combine both—keeping the staging URL while bringing in the v4 timeout and signature settings. Likewise, in CSS, check the surrounding selector and media queries rather than picking one colour value at random.
Once you have edited the file and removed every <<<<<<<, =======, and >>>>>>> marker, inspect your changes:
git diff -- config-env.js styles.css
Test before you stage anything
A file that parses cleanly can still be subtly broken at runtime. Run your actual test suite and build before staging a single file:
npm test
npm run build
(Or dotnet test, composer test, etc., depending on your stack.) Check the specific feature touched by the merge—payment callbacks, route prefixes, database migrations, or asset paths—not just whether the compiler is happy.
If the merge turns into a tangle you do not fully understand, bail out cleanly:
git merge --abort
That puts you right back at the clean intermediary branch state so you can regroup or ask for help.
Commit only the resolution and open the PR
When tests pass, stage only the files you intentionally resolved:
git add config-env.js styles.css
git status
git diff --cached
git commit -m "Merge patch/payment-gateway-v4 into staging"
Avoid running git add . out of habit; it is too easy to sweep in generated build artifacts, .DS_Store, or local debug logs. Once committed, push the intermediary branch:
git push -u origin chore/merge-patch-gateway-to-staging
Open a pull request from chore/merge-patch-gateway-to-staging into env/staging-integration-core. In the PR description, link the original patch or ticket, list each conflicted file with a one-line explanation of what you kept or combined, and note which tests passed. A reviewer should never have to guess why a config key changed.
Knowing when to pause and ask
Stop immediately if a conflict touches business logic you do not own, irreversible database migrations, production credentials, or payment settlement code whose intent is unclear. Use Git history to gather context first:
git log --merge --oneline -- config-env.js
git blame -L 20,40 -- config-env.js
Then ask the original author a sharp question: “Staging sets the callback URL for the test merchant, while v4 adds a 15-second timeout and a new signature header—should we keep the staging URL and merge both v4 fields?” That gets an answer in two minutes; “Which version should I keep?” usually gets a shrug.
For related guides that complement this checklist, see:
- Your Website Is Broken in the Browser: A Practical DevTools Guide to Finding the Real Cause
- Your Website Works for You—But Can Everyone Use It? A Practical Accessibility Checklist
- PHP2Shell Explained: What the New PHP Vulnerability Means for Ordinary Website Owners
Conflict resolution stops being stressful the moment you treat it as careful integration work instead of emergency text editing. Keep the shared destination untouched, resolve and test on a disposable branch, and let a pull request document the final call.