Add rules support for branch manipuation

Thanks to dfranca for working on this with me.