How do I programmatically add a field to an existing fieldset that's part of the user entity? I'd like to know how to add a field to an existing fieldset in a user entity

I've seen this example:

Add Fields to Field Group programatically
https://drupal.stackexchange.com/a/71902/1082

$groups = field_group_read_groups(array(
    'name' =&gt; 'node',
    'bundle' =&gt; 'article',
    'view_mode' =&gt; 'full'));
  $your_group = $groups['node']['article']['form']['group_your_group'];
  $your_group-&gt;children[] = 'field_your_new_field';
  field_group_group_save($your_group);


But I'm unsure what to supply for 'name' and 'bundle' and also what to supply for the line

$your_group = $groups['node']['article']['form']['group_your_group'];
I think you should try hook_form_alter. try this may it helpful to you.

function mymodule_form_alter(&amp;$form, $form_state, $form_id) {

  // Check your form-ID 
  if ($form_id == 'user_profile_form') {
    // Creating custom field
    $form['new_field'] = array(
      '#weight' =&gt; 4,
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('New Field Name'),
    );
  }
  // Attach to the existing group
  // Suppose group machine-name is group_general
  $form['#group_children']['new_field'] = 'group_general';
}