Add V to the graph G and draw edges, i.e. morphisms, from V to every point in G. The edges of D remain. If this augmented diagram commutes, we have an object in the new category.
Let two such diagrams, built from V0 and V1, have a morphism for every morphism from V0 to V1 that makes the composite diagram on G∪V0∪V1 commute. Remember, vertices need not be assigned distinct objects, so V0 and V1 could be the same entity. Let's see if this category makes sense.
Let V0 and V1 represent the same object and run the identity morphism between them. If D∪V0 and D∪V1 are the same diagram, then the composite D∪V0∪V1 is commutative. The identity morphism in the original category implies an identity morphism in the new category.
Next verify composition, from V0 to V1 to V2. We need to show the composite is a commutative diagram. Supppose two paths start at X and end at Y, and imply different morphisms. Let these be the shortest paths that violate commutativity. If X is not V0 then there is no way to get to V0, so V0 is not part of either path. Both paths live in D∪V1∪V2, which is commutative. So we can assume X = V0.
If neither path moves through V2 then they both live in D∪V0∪V1, which is commutative. Let the first path include V2, and the only way to do that is to go from V0 to V1 to V2. If the second path goes from V0 to V1 we could delete the leading edge, and start at V1, and find two shorter paths that imply different morphisms. This is a contradiction, so the second path goes from V0 straight into G. Here are some equalities among implied morphisms. Remember that X is V0, and Y is some point in G.
X → path1 → Y =
X → Y =
X → V1 → Y =
X → ( V1 → V2 → Y ) =
X → V1 → V2 → Y =
X → path2 → Y
Any path that begins with V0→V1→V2 could begin with V0→V2. Bringing in this implied morphism, the third side of the triangle, does not affect commutativity, and the new edge becomes the third morphism in our new category. Thus morphism composition is well defined. Furthermore, it inherits associativity from the original category.
Remember that T specifies an object V, and morphisms from V to all the objects in G. In other words, the edges from V to G are part of T.
Let D be the trivial graph on G, where there are no edges, and let T be a terminal object. Let S be another object on G∪U. Now the morphisms from S to T are derived from the morphisms from U to V. There is one such morphism, since T is terminal. In other words, there is one morphism from U to V that makes the diagram commute. And this holds for every U. This is the definition of product. The terminal object in the new category is the product in the original category.
The initial object in the new category is the colimit of D. If D is merely G with no edges, the colimit is the coproduct in the original category.
Suppose U and V are both limits of D. Let f and G be the antiparallel morphisms from U to V and from V to U. The morphism fg maps U into U, and since the diagram commutes, this has to be the identity morphism from U into U. Thus f and G are inverses and we have equivalence.
A similar argument shows the colimit is unique up to equivalence.