Refactor git checkout logic