This and several related questions illustrate the advantages of having the notion of the fundamental groupoid $\pi_1(X,A)\;\;$ on a set $A$ of base points, since one may want to identify some of the points of $A$. There is an appropriate groupoid construction, due to Philip Higgins, see Categories and Groupoids. Given a groupoid $G\; $ with object set $X$ and a function $f: X \to Y\;\;$ there is a groupoid $f_*(G)\; $, or $U_f(G)\; $ in C&G, Chapter 8, which is universal for morphisms from $G$ whose object map factors through $f\;$. The construction of this generalises that of free groups and of free products of groups.
The application of this to fundamental groupoids is given in Topology and Groupoids, p. 343.
This may seem difficult for beginners; but it follows the idea of choosing algebraic structures which well model the geometry, and has the advantage of dealing with two group theory constructions often given separate expositions.
The philosophical point here is that to model the gluing of spaces, one needs algebraic objects with structure in a range of dimensions starting with $0$, since in homotopy theory identifications in low dimensions have homotopical effects in high dimensions. Groupoids may be seen as having structure in dimensions $0,1\;$. This philosophy does carry over to higher dimensions, but one needs appropriate models.