Git: Undo a merge solution

# you are on the dev branch
git checkout master
git merge dev 
# here you've merged the dev branch into master but actually you wanted to perform a --no-ff merge
git reset --hard origin/master to undo the above merge: reset the master branch to the pre-merge state
git merge --no-ff -m 'my custom merge message' dev # now you can perform the merge you actually wanted

To undo an already pushed merge, you have to "git reset --hard 'the preceding commit ID of your last push to the master branch'" and repush the newly created commit using the -f flag.