Saving fields to a GlobalSet
Something like this should work:

// Generate name and handle.
$globalSetName = "My Global Set";
$globalSetHandle = lcfirst(str_replace(" ","", ucwords($globalSetName)));

// Create a global set
$globalSet= new GlobalSetModel();
$globalSet-&gt;name = $globalSetName;
$globalSet-&gt;handle = $globalSetHandle;

// get all the fields from  fieldgroup
$fields = $fieldGroup-&gt;getFields();

// Get ids of the fields.
$fieldIds = array();
foreach ($fields as $field)
{
    $fieldIds[] = $field-&gt;id;
}

// Assemble the field layout
$globalSetLayout = craft()-&gt;fields-&gt;assembleLayout(
    array(
        'Content' =&gt; $fieldIds,
    )
);

// Set the field layout type.
$globalSetLayout-&gt;type = ElementType::GlobalSet;

// Set field layout on global set.
$globalSet-&gt;setFieldLayout($globalSetLayout);

// Save global set.
craft()-&gt;globals-&gt;saveSet($globalSet);