you have a pushd before popd in the same if. If branch name is speciffied, we change directory inside the repo and do a checkout of that branch name. Then, we get back to out old CWD. pushd and popd are only needed if a branch name is passed to the script