Any person confined in jail for failing to enter into an undertaking to keep the peace may prosecute a writ of habeas corpus as provided in this chapter; but such writ can be heard only by a judge of the circuit court, who may discharge the applicant, remand him to jail or reduce the amount of the undertaking as may seem right. If the amount of the undertaking is reduced, the sheriff must discharge the applicant upon the entering into the undertaking in the sum fixed by such judge.
Ala. Code § 15-21-2 (1975)