I have downloaded whole working tree with the following command:
repo init -u https://android.googlesource.com/platform/manifest
repo sync -j8
if the branch you are in and the branch you will switch to has the same manifest.xml file, then you can use the following commands to do that.
repo forall -c git fetch aosp --tags
repo forall -c git checkout -b john5.1.1_r14_api22 android-5.1.1_r14
also see details in http://johnliao52.github.io/2016/03/27/git-repo-skills.html