Got it — you're describing a very common setup (staging → main promotion flow), but you're running into a classic problem because of how you're merging.
Let's break it down:
Why this happens:
- You have
staging as your working branch.
- You create a PR from
staging → main.
- You squash and merge the PR into
main.
- Squash and merge creates a new commit on
main that doesn't exist on staging.
- Therefore,
main is now 1 commit ahead of staging.
- When you later try to PR from
staging to main again, Git sees a divergence and potential conflicts.
Why squash and merge causes this:
- Squash and merge rewrites the commit history into a single new commit.
- That new commit does not exist in
staging.
- So
staging and main histories are no longer aligned.
Best practices to fix this:
You have two main options:
Option 1: Use Merge Commit instead of Squash Merge
- When you PR from
staging → main, use a regular merge commit (not squash).
- This way, the commit history is preserved.
main will have the same commits as staging, plus a merge commit.
- No divergence, no conflicts.
✅ Pros:
- Clean history.
- No conflicts.
- Easy to track what was merged.
❌ Cons:
- If your
staging branch has messy commits, they will all show up in main.
Option 2: After merging, sync main back into staging
- After you squash and merge
staging → main, immediately merge main back into `staging.
- This way,
staging picks up the new commit from main, and they are in sync again.
Example:
git checkout staging
git pull origin staging
git merge origin/main
git push origin staging
✅ Pros:
- You can still squash and merge to keep
main clean.
staging stays up to date.
❌ Cons:
staging will have merge commits from main.
- Slightly more manual work.
Option 3: Rebase staging onto main
- After merging to
main, you could rebase staging onto main to realign the histories.
Example:
git checkout staging
git pull origin staging
git fetch origin main
git rebase origin/main
git push --force-with-lease origin staging
✅ Pros:
- Very clean history.
- No merge commits.
❌ Cons:
- Rebasing can be dangerous if multiple people are working on
staging.
- Requires force-pushing.
TL;DR Recommendation:
If you want the simplest, safest flow:
- Use regular merge commits when merging
staging → main.
- Avoid squash merges for this particular PR.
- Keep squash merges for feature branches into
staging, but not for staging into main.
If you really want to keep main super clean with squash merges:
- After merging, merge
main back into `staging immediately.
Bonus: How big teams usually do it
- Feature branches → squash merge into
staging.
staging → merge commit into main (no squash).
main is protected, only updated via PRs from staging.
staging is reset or synced after each release.
Would you like me to also show you a visual diagram of this flow? 🚀
It can make it even clearer!