Understanding why people join, stay, or leave social groups is a central question in the social sciences, including computational social systems, while modeling these processes is a challenge in complex networks. Yet, the current empirical studies rarely focus on group dynamics for lack of data relating opinions to group membership. In the NetSense data, we find hundreds of face-to-face groups whose members make thousands of changes of memberships and opinions. We also observe two trends: opinion homogeneity grows over time, and individuals holding unpopular opinions frequently change groups. These observations and data provide us with the basis on which we model the underlying dynamics of human behavior. We formally define the utility that members gain from ingroup interactions as a function of the levels of homophily of opinions of group members with opinions of a given individual in this group. We demonstrate that so-defined utility applied to our empirical data increases after each observed change. We then introduce an analytical model and show that it accurately recreates the trends observed in the NetSense data.