Sorry about the mistake in the comment. First of all, for a proper, locally finitely presented morphism of schemes, $\pi:X\to S,$ with $S$ excellent (e.g., a finite type scheme over a field or over $\text{Spec}\ \mathbb{Z}$), for a flat, affine group scheme $\rho:G\to X$, the set-valued functor $\pi_* G$ is representable by a group scheme over $S.$ This follows, for instance, from Lemma 2.3.3 of the following article. MR2233719 (2008c:14022) <br> Lieblich, Max(1-PRIN) <br> Remarks on the stack of coherent algebras. <br> Int. Math. Res. Not. 2006, Art. ID 75273, 12 pp. <br> https://arxiv.org/pdf/math/0603034.pdf However, it is not true that $\pi_*G$ is always affine for $\pi$ a proper, locally finitely presented morphism and $G/X$ a flat, affine group scheme. Let $S$ be $\mathbb{A}^2_k,$ the affine plane. The open complement, $j:V\hookrightarrow \mathbb{A}^2_k,$ is a flat morphism, but it is not affine. Let $f:X\to S$ be the blowing up of $\mathbb{A}^2_k$ at the origin. This is a proper morphism. Denote by $E$ the exceptional divisor of $f$. Denote by $U$ the open complement of $E$. As the complement of a Cartier divisor in a smooth scheme, the open immersion $i:U\hookrightarrow X$ is an affine morphism. Let $\rho:G\to X$ denote an $X$-scheme with two connected components, one of which maps isomorphically to $X$, $$\rho_e:G_e \xrightarrow{\cong} X,$$ and the second of which maps isomorphically to $U$, $$\rho_{\sigma}:G_{\sigma} \xrightarrow{\cong} U.$$ There is a unique structure of $X$-group scheme on $G$: the identity section is the inverse isomorphism of $\rho_e,$ and the multiplication morphism, $$G_\sigma\times_X G_\sigma \to G_e,$$ is the unique open immersion of $X$-schemes. The $X$-group scheme $G$ is flat and affine. Yet the pushforward $\pi_*G$ is a disjoint union of a copy of $S$ and a copy of the open immersion $j:V\to S.$ This open immersion is not affine.