Improve origin branch handling