If the defendant is committed to jail for a bailable offense, the magistrate shall endorse on the commitment the amount of the bail required, and sign the endorsement. The sheriff of the county to which the defendant is committed may discharge the defendant, upon the defendant giving sufficient bail in the sum required, and make immediate return to the court to which the defendant is bound to appear of the bail bond or undertaking.