A witness required to give bail who fails or refuses to do so shall be committed to jail as in other cases of a failure to give bail when required, but shall be released from custody upon giving such bail.