Best way to automate auto-merging git branches

17 Views Asked by At

I have a repo set up with Production and QA branches. To automate merging fixes in prod down to dev, I have a job setup to run after each git merge that will do the following:

git fetch origin
git checkout -b mergeProdToQa origin/QA
git merge --no-verify --ff origin/Prod
./my_automerge_validations-qa.sh
git pull --rebase origin QA
git push origin QA

git fetch origin
git checkout -b mergeQaToDev origin/Dev
git merge --no-verify --ff origin/QA
./my_automerge_validations-dev.sh
git pull --rebase origin Dev
git push origin Dev

The reason I have put git pull --rebase origin QA is because the automerge script takes up to 15 minutes to run and the repo is used by many people and constantly receives commits, so the push was running into the refs out of date error.

However, I have noticed there are few cases where the rebase is counter-productive. When there is a merge conflict in prodToQa, the rebase in qaToDev overwrites the merge resolution that I make so it's not recognized anymore, and will throw another merge conflict. Also, in cases where there is a merge conflict as well as a rebase conflict, I have had to resolve the merge by keeping none of the merged changes, then cherry-pick the commit instead as the rebase resolution isn't saved (rerere is not an option for us).

Wondering if anyone has ideas on a better solution for this? Thanks

0

There are 0 best solutions below