Have you ever fall in the situation where the commit chain from the main branch (prod) differs from the staging branch, either cause by:
- A cherry-picked commit to main
- A bunch of commits squashed and added as a single commit to the main branch
Well it has happened to me a couple times in different teams, and on each case several approaches had bumped up from my colleagues:
- Address the conflicts manually? ๐ฅ
- Revert (hard reset main) the conflicting commits? ๐ฐ
- Hard push (force) the staging branch to main? ๐
To be honest I'm not a fan of forcing things, I like my Pull Requests to merge soothly into main ๐
so I'll give you the solution to this problem, which I've called Conciliation Branch even though I'm not sure if the term already exist or not, but it's an approach I've made several times to solve this. (as a git lover)
Well let's jump in!
Commands:
Note: all steps we're doing through terminal
$: git fetch
$: git checkout staging
# in case we're not up-to-date with upstream
$: git merge origin/staging
# Create a conciliation branch from staging-branch
$: git checkout -b <conciliation-branch-name>
# merge master back into staging taking "ours" preference
$: git pull -s ours origin master
# push new branch
$: git push <conciliation-branch-name>
And that's it!
Now all you need to do is create a Pull request from your new conciliation-branch
to staging-branch
That will allow you then after merged to now open a new Pull Request from staging-branch
to master
smoothly ๐ ๐ฅณ
Thanks for reading!, Hope this could help you a lot.
Top comments (0)