Convert Views display to Master display

Thanks to jedihe for posting this great tip: https://www.drupal.org/node/2313791#comment-11469881

$view = views_get_view('machine_name_of_my_view'); 
$source_display = 'machine_name_of_the_overridden_display'; 

foreach (array_keys($view->display[$source_display]->display_options['defaults']) as $key) {
 if (!empty($view->display[$source_display]->display_options[$key])) { 
   $view->display['default']->display_options[$key] = $view->display[$source_display]->display_options[$key]; 
 } 
 unset($view->display[$source_display]->display_options[$key]); 
} 
unset($view->display[$source_display]->display_options['defaults']); 

// Uncomment and run once you are sure to save the changes.
$view->save();