For the sake of building previous releases, fetching the whole history of the repository for each version seems to be overkill as it takes much more time, bandwidth and disk space than necessary. Create a shallow clone instead with history truncated to the one commit of the version tag, which is directly checked out in the same command. This has the nice side-effect that we can remove the extra git checkout step after as it's not needed anymore.
Note that it might look confusing to pass a tag to a parameter named --branch, but the git-clone manpage explicitly states that this is supported.