Suppose that $\pi: X \to S$ is a proper morphism of schemes, and $G \to X$ is a flat affine algebraic group scheme over $X$. Is the push-forward $\pi\_\* G$ also affine? 


I'd be happy to assume more -- say that $\pi$ is smooth, and that $G$ is smooth over $X$, or even a torus...



push-forward of linear algebraic group schemes
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 finitely presented, flat, affine group scheme $\rho:G\to X$, the set-valued functor $\pi\_\* G$ is representable by a group ~~scheme~~ **algebraic space** that is locally finitely presented over $S$. (**Ed.** Thanks to @nfdc23 for pointing out that Lieblich's result only gives an algebraic space.) This follows, for instance, from Lemma 2.3.3 of the following article.


MR2233719 (2008c:14022)   

Lieblich, Max(1-PRIN)   

Remarks on the stack of coherent algebras.   
 
Int. Math. Res. Not. 2006, Art. ID 75273, 12 pp.   

<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.


