Cannot remove the primary group of user

If you get this message :

groupdel: cannot remove the primary group of user

While you try to delete a user with this command :

sudo groupdel UserGroup 

Then try this :

sudo usermod -g UserName UserGroup
sudo groupdel UserGroup

Of course, you should know to what group is attached the user.