How do I make git automatically run git mergetool
for any merge conflict? This should apply for all merges, using merge
, rebase
, pull
, etc.
We can manually resolve the merge conflict by editing the content in the bottom pane, and then saving the file using :wqa (Write and Quit all files). Once the conflict resolution is successful, the merged file will be staged for commit. git commit -m 'Merged from multiple branches' .
A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches.
A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.
You cannot (yet) make git do this.
This may or may not be an acceptable workaround.
Create a function in your ~/.bashrc
:
git() { if [[ $1 == "merge" ]] || [[ $1 == "rebase" ]] || [[ $1 == "pull" ]]; then command git "$@" rc=$? if [[ $rc == 1 ]]; then echo "There are conflicts, better run git-mergetool!!!" # There might be some other condition that returns a '1', # if so you can add another check like this: # if grep Conflicts $(git --git-dir)/MERGE_MSG; command git mergetool fi else command git "$@" fi }
Mergetool isn't invoked when it merges:
$ git merge non_conflicting_branch Merge made by the 'recursive' strategy. bar | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 bar
Mergetool is called when there are conflicts:
$ git merge conflicting_branch Auto-merging foo CONFLICT (content): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result. There are Conflicts, better run git-mergetool!!!
Mergetool is not called on other errors:
$ git merge adasds fatal: adasds - not something we can merge
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With