Free groups
Let $S$ be a set (the alphabet) and suppose $S\inv = \sb{s\inv}{s\in S}$ is disjoint from $S$.
A word in $S$ is a (possibly empty) finite sequence $(x_1, \ldots, x_n)$ of elements in $S\cup S\inv$.
An elementary reduction of a word removes a subword $(s, s\inv)$ or $(s\inv, s)$. A word is reduced if it does not admit any elementary reductions.
The free group $F(S)$ on the alphabet $S$ is the set of reduced words in $S$, with the operation being concatenation and then applying elementary reduction until the word is reduced.
Define a function $ι: S \to F(S)$ sending $s \mapsto (s)$.
For any group $H$ and alphabet $S$, the function $$ \begin{align*} \set{\text{group homomorphisms $F(S)\to H$}} &\to \set{\text{functions $S\to H$}} \\ \varphi &\mapsto \varphi\circ ι \end{align*} $$ is a bijection. That is, for any (set) functions $ϕ: S\to H$, there exists a unique group homomorphism $\varphi:{}$$F(S)$${}\to H$ such that this diagram commutes:
$F(S)$ is the unique group (up to isomorphism) satisfying the condition of this lemma.
Let $S$ be an alphabet and $R \subseteq{}$$F(S)$ be a subset.
The group with generators $S$ and relations $R$ is defined as the quotient $$ \begin{align*} \langle S \mid R\rangle = F(S)\; /\; \langle \langle R\rangle\rangle \end{align*} $$ where $\langle \langle R\rangle\rangle$ is the largest normal subgroup containing $R$: $$ \begin{align*} \langle \langle R\rangle\rangle = \sb{\prod_{i=1}^{n} g_i\, r_i^{ε_i}\, g_i\inv}{g_i\in F(S), \; r_i\in R, \; ε_i \in \set{\pm 1}}. \end{align*} $$ The data $(S,R)$ is called a presentation of the group.
If $S$ and $R$ are finite, we call it a finite presentation.
For any group $H$ and group presentation $\langle S \mid R\rangle$, $$ \begin{align*} \set{\text{group homomorphisms } \langle S\mid R\rangle \to H} &\to \sb{\text{functions }ϕ: S\to H}{\varphi(r)=1 \;\forall r\in R} \\ ψ &\mapsto ψ \circ q \circ ι \end{align*} $$ is a bijection, where $q: F(S) \to \langle S\mid R\rangle$ is the quotient map and $\varphi: F(S)\to H$ is given by the universal property of free groups.
That is, for any (set) function $ϕ: S\to H$ such that $ϕ(s_1)^{ε_1} \ldots ϕ(s_n)^{ε_n} = 1$ for all $(s_1^{ε_1}, \ldots, s_n^{ε_n})\in R$, there exists a unique group homomorphism $ψ: \langle S\mid R\rangle\to H$ such that this diagram commutes:
Any group $G$ has a canonical presentation: the identity $\id_G: G\to G$ induces a surjective homomorphism $\varphi : F(G) \to G$. This further induces $ψ: \langle G\mid \ker \varphi\rangle \to G$, which is an isomorphism by the first isomorphism theorem.
Let $G_1$ and $G_2$ be any groups, given by the presentations $\langle S_1 \mid R_1\rangle$ and $\langle S_2 \mid R_2\rangle$, where $S_1 \cap S_2 = \emptyset$.
Define the free product as $$ \begin{align*} G_1 * G_2 = \langle S_1 \cup S_2 \mid R_1 \cup R_2\rangle. \end{align*} $$
The inclusions $S_i\to S_1 \cup S_2 \to F(S_1 \cup S_2)\to G_1 * G_2$ induce canonical homomorphisms $G_1 \xrightarrow{j_1} G_1 * G_2 \xleftarrow{j_2} G_2$.
Given a group $H$ and homomorphisms $G_1 \xleftarrow{i_1} H \xrightarrow{i_2} G_2$, define the free product with amalgamation over $H$ to be the quotient $$ \begin{align*} G_1 *_H G_2 = (G_1 * G_2) \;/\; \langle \langle j_1(i_1(h)) \cdot (j_2(i_2(h)))\inv \mid h\in H\rangle\rangle. \end{align*} $$
The free product is the free product with amalgamation over the trivial group.
The construction ensures this commutes:
Let $K$ be any group, and $G_1 *_H G_2$ be an amalgamated free product.
For any homomorphisms $ϕ_1: G_1 \to K$ and $ϕ_2: G_2\to K$ satisfying $ϕ_1 \circ i_1 = ϕ_2 \circ i_2$, there exists a unique homomorphism $ϕ: G_1 *_H G_2 \to K$ such that $ϕ_1 = ϕ \circ j_1$ and $ϕ_2 = ϕ \circ j_2$, i.e. this diagram commutes: