Created
July 5, 2019 15:06
-
-
Save nikolareljin/e72ef7a92cc00c54040984339542fe37 to your computer and use it in GitHub Desktop.
Prepare two branches for Pull Request. Make sure there will be no merge conflicts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#=========================================== | |
# Use: | |
# merge_conflict.sh <SRC BRANCH> <DST BRANCH> | |
# merges changes from SRC branch -> DST branch | |
# | |
# Makes sure we will have no merge conflicts so | |
# we could Open PR for SRC branch. | |
# | |
# Creates TMP branch while performing the merge. | |
#=========================================== | |
SRC_BRANCH=$1 | |
# This should be the "main" branch of the repository. | |
DST_BRANCH=$2 | |
if [[ -z ${DST_BRANCH} ]]; then | |
DST_BRANCH="production" | |
fi; | |
TMP_BRANCH="tmp" | |
echo "fixing merge conflict" | |
git checkout . | |
git pull --all | |
git checkout ${SRC_BRANCH} | |
git pull --all | |
echo "Create TMP branch" | |
git checkout -b ${TMP_BRANCH} | |
echo "Fix merge conflicts" | |
git merge -s ours "${DST_BRANCH}" | |
git checkout "${TMP_BRANCH}" | |
echo "Merge ${TMP_BRANCH} -> ${SRC_BRANCH}" | |
git checkout "${SRC_BRANCH}" | |
git merge "${TMP_BRANCH}" | |
echo "Rebase to ${DST_BRANCH}" | |
git rebase "${DST_BRANCH}" | |
echo "Show changes in two branches" | |
git diff "${DST_BRANCH}" | |
echo "Remove TMP branch" | |
git branch -d "${TMP_BRANCH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment