[git] Extract the branch switch into a function