In this study, an injectable, porous, and Mg2+-loaded hydrogel with the ability to scavenge local reactive oxygen species was developed for bone-repair applications. Alendronate sodium with a specific binding affinity to Mg2+ was incorporated into the hydrogel through a Schiff's base reaction with oxidized dextran. The porous hydrogel, which was cross-linked by catechol-modified chitosan to maintain its mechanical properties, showed enhanced cell viability, proliferation, differentiation of human bone marrow stromal cells in vitro, and osteogenic property in a rat-femur defect model. The hydrogel promoted the regeneration of bone tissue including ossification and particularly endochondral ossification, indicating a progressive healing process. The formed bone tissue exhibited a dense and layered structure, substantiating its effectiveness in osteogenic differentiation. The hydrogel also affected the polarization of macrophages and inhibited the M1 phenotype associated with tissue repair and regeneration, exhibiting the potential to reduce local inflammatory response and benefit bone repair. Overall, the hydrogel can be anticipated as a promising biomaterial for bone repair because of its multiple biofunctions including enhanced osteogenesis and endochondral ossification, and modulation of inflammation.