Herein, we synthesized porous one-dimensional graphitic carbon nitride (g-C3N4) doped atomically with metal atoms (M/g-C3N4) (M = Cu, Mn, and Fe) for the electrochemical and photo-electrochemical hydrogen evolution reaction (HER). This is driven by the direct acidification of an aqueous solution of metal precursors and melamine followed by pyrolysis at 550 °C under N2. The as-obtained M/g-C3N4 had well-defined pore sizes (5–10 nm), nanofibers (90 ± 5 nm in width and 5 ± 1 μm in length) morphology, high surface area, and M atomic contents (1.7 ± 0.2 wt.%). The HER performance is in the order of Cu/g-C3N4 > Fe/g-C3N4 > Mn/g-C3N4 in terms of the overpotential, onset potential, H2 production rate, and mass/specific activity. Notably, Cu/g-C3N4 achieved turnover frequency (TOF) close to that of commercial 10 wt.% Pt/C, but higher mass/specific activity and great H2 production rate of (222.15 μmol· g−1·h−1). This work open the doorway for the utilization of g-C3N4 doped metal-atoms at low content in electrocatalytic and photocatalytic HER.