Definition of Epimorphism in Category Theory Given a morphism $f : A \to B$, $f$ is en epimorphism iff $\forall g_1, g_2 : B \to C. f \circ g_1 = f \circ g_2 \implies g_1 = g_2$
In words, a morphism $f : A \to B$ is epic if it has the property, that if any two morphisms $g_1, g_2 : B \to C$ are equal composed with $f$ then they are also equal on their own.
I don't understand the point of this definition. In fact, I looked up the above definition from Wikipedia after also struggling with the definition given in this lecture:
$$\left[\forall c. \forall g_1, g_2 : b \to c. g_1 \circ f = g_2 \circ f \implies g_1 = g_2 \right]\implies f : a \to b \text{ is an epimorphism}$$
The motivation for this has to do with surjections and is given in the lecture before. But I just don't get the motivation he presents there.
Could somebody explain the motivation with the surjection the lecturer gives in different words? Or explain the idea behind this definition from another angle?
(I just started out learning about this by watching the other vidoes in the series of lectures linked, which were only 2, so I do not have any background knowledge besides some very basic stuff.)
 A: An epimorphism is a generalization of a surjective function.  Suppose we are working in the category of sets.  The objects are sets, and the morphisms are functions between sets.  Let $f: A \rightarrow B$ be a function between two sets.
Lemma: $f$ is surjective if and only if the following condition holds: for any set $C$, and any pair of functions $g_1, g_2: B \rightarrow C$, if $g_1 \circ f = g_2 \circ f$, then $g_1 = g_2$.
Proof: First suppose $f$ is surjective.  Under the assumption that $g_1 \circ f = g_2 \circ f$ for a given set $C$ and a pair of functions $g_1, g_2: B \rightarrow C$, we need to show that $g_1 = g_2$.  In other words, for any element $b \in B$, we need to show that $g_1(b) = g_2(b)$.  But $f$ is surjective, so we can choose an element $a \in A$ such that $f(a) = b$.  Then $g_1(b) = g_1 \circ f(a) = g_2 \circ f(a) = g_2(b)$.
For the converse, assume that $f$ is not surjective.  Let $C = \{0,1\}$, and define a function $g_1: B \rightarrow C$ by setting $g_1(b) = 0$ for all $b$.  Define another function $g_2: B \rightarrow C$ by setting $g_2(b) = 0$ if $b$ is in the image of $f$, and otherwise setting $g_2(b) = 1$.  Since $f$ is not surjective, we see that $g_1 \neq g_2$.  Yet $g_1 \circ f = g_2 \circ f$.  $\blacksquare$
Now instead of the category of sets, suppose we are in an arbitrary category $\mathcal C$.  It no longer makes sense to talk about a morphism being surjective, since a morphism need not actually be a function between sets.  But the equivalent condition to surjectivity in the statement of the lemma still makes perfect sense in an arbitrary category, so that statement is a natural generalization to take as the definition of a "surjective morphism," or "epimorphism."
So, now we have a definition of an epimorphism in an arbitrary category, which coincides with the definition of surjective when we are in the category of sets.  At first glance, this may seem like a stupid definition, which just happens to agree with the definition of surjectivity in a special case.  But there are many examples in algebraic geometry or number theory where one sees that this is really a "good" definition.  Here are a couple:
1 .  The popular and useful "functor of points" view.  Let $f: A \rightarrow B$ be a morphism in a category $\mathcal C$.  Suppose the collection $\textrm{Hom}(A',B')$ of morphisms in $\mathcal C$ between any objects $A', B'$ of $\mathcal C$ form a set.  For each object $C$ in $\mathcal C$, we get a function between the sets:
$$f_{\ast}:\textrm{Hom}(C,A) \rightarrow \textrm{Hom}(C,B)$$
$$g \mapsto f \circ g$$
In fact, one can identify the objects $A, B$ with the contravariant functors $\textrm{Hom}(-,A), \textrm{Hom}(-,B): \mathcal C \rightarrow \textrm{Set}$.  The Yoneda lemma makes this precise.
Then $f$ is an epimorphism if and only if $f_{\ast}$ is an injective function for all objects $C$!
2 .  Contravariant equivalence, and the tendency of monomorphisms to be the same thing as injective morphisms.  In many categories, even if the objects are sets and the morphisms are certain functions between the sets, epimorphisms do not need to be surjective functions.  This is true in the category of rings, for example.  However, monomorphisms (morphisms with the opposite property: $f\circ g_1 = f\circ g_2$ implies $g_1 = g_2$) are often easier to characterize.  In the category of rings, monomorphisms are the same thing as injective homomorphisms.
Now, let $\mathcal C$ be the category of affine varieties over an algebraically closed field $k$, and $\mathcal D$ be the category of finitely generated, reduced $k$-algebras.  General algebraic geometry shenanigans tells you that these categories are antiequivalent: to any morphism of varieties $\phi: X \rightarrow Y$ we can associate a homomorphism of $k$-algebras $\phi^{\ast}: k[Y] \rightarrow k[X]$, and conversely to a homomorphism $\psi: A \rightarrow B$, we can associate a morphism of varieties $\psi^{\ast}:\textrm{Spm}(B) \rightarrow \textrm{Spm}(A)$.  Here $k[X]$ is the coordinate ring of $X$, and $\textrm{Spm}(A)$ is the space of maximal ideals of $A$.  These operations are inverse to each other in the sense that we can naturally identify $\textrm{Spm}(k[X])$ and $X$, as well as $k[\textrm{Spm}(A)]$ with $A$.
The point of these categories being antiequivalent is that everything gets reversed.  An epimorphism of varieties $\phi$ would translate to a monomorphism of $k$-algebras $\phi^{\ast}$.  But we know what the monomorphisms in the category of $k$-algebras are!  They are exactly the injective homomorphisms.  And to say that a given $k$-algebra homomorphism $\phi^{\ast}$ is injective has a nice equivalent characterization in terms of the morphism of varieties $\phi$ it came from: the image of $\phi$ is dense in $Y$.  This isn't quite the same thing as $\phi$ being surjective, but it is pretty close.
