My git repository has 2 branches: master and develop. I want a script that merges all changes from develop to master automatically.
I used Jenkins: The Git plugin clones the repository and then this script (the 'version' variable is a job parameter) is run:
# merge
git checkout -b develop origin/develop
git checkout master
git merge -Xtheirs --squash develop -m "v${version}"
# commit
git commit -m "v${version}"
# tag
git tag v${version} -m "v${version}"
# push
git push origin v${version}
I tried it on a test repository and it fails with:
git merge -Xtheirs develop
CONFLICT (delete/modify): test.txt deleted in develop and modified in HEAD. Version HEAD of test.txt left in tree.
Automatic merge failed; fix conflicts and then commit the result.
How do I resolve this conflict automatically? I want the script to always add/modify/delete files according to the 'develop' branch, since master is never touched anyway...
The
-X theirs
merge strategy only works to resolve conflicting hunks within a file. The documentation for these options is in thegit-merge
man page: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: