DEV Community

Cover image for Conciliation Branch in Git
Kevin J. Estevez
Kevin J. Estevez

Posted on • Edited on

Conciliation Branch in Git

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 cherry-pick case
  • A bunch of commits squashed and added as a single commit to the main branch squashed commits case

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>
Enter fullscreen mode Exit fullscreen mode

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)