Script to merge 2 git branches automatically? Script to merge 2 git branches automatically? jenkins jenkins

Script to merge 2 git branches automatically?


The -X theirs merge strategy only works to resolve conflicting hunks within a file. The documentation for these options is in the git-merge man page:

      ours           This option forces conflicting hunks to be auto-resolved           cleanly by favoring our version. Changes from the other tree           that do not conflict with our side are reflected to the merge           result.           This should not be confused with the ours merge strategy, which           does not even look at what the other tree contains at all. It           discards everything the other tree did, declaring our history           contains all that happened in it.       theirs           This is opposite of ours.

In this case, one branch has deleted the file while the other has modified it, which is a distinct case from a simple conflicting hunk between two branches that have made different modifications.


5 years old.... But still relevant.

Here's my solution:I delete the master branch and create a new master branch from the branch I want to 'merge' from:

GIT_BRANCH_TO_MERGE_FROM=`git symbolic-ref HEAD | sed 's!refs\/heads\/!!'`GIT_BRANCH_TO_MERGE_TO="master"git checkout "${GIT_BRANCH_TO_MERGE_TO}"git checkout "${GIT_BRANCH_TO_MERGE_FROM}"# Delete TO branchgit branch -D "${GIT_BRANCH_TO_MERGE_TO}" || echo "Failed to delete ${GIT_BRANCH_TO_MERGE_TO}"git push origin :"${GIT_BRANCH_TO_MERGE_TO}" || echo "Failed to push ${GIT_BRANCH_TO_MERGE_TO} delete to origin"# Create TO branchgit checkout -b "${GIT_BRANCH_TO_MERGE_TO}" || echo "Failed to create local branch ${GIT_BRANCH_TO_MERGE_TO}"git push origin "${GIT_BRANCH_TO_MERGE_TO}" || echo "Failed to push ${GIT_BRANCH_TO_MERGE_TO} to origin"