This is the way that github recommends (https://help.github.com/articles/creating-project-pages-manu...).
A separate folder for the gh-pages branch makes sense because this branch has nothing in common with any of the other branches. It doesn't share any code or commits with your master branch.
The repository actually has two base commits and it's like two repositories contained in one. Thus needing two separate folders.
Code section 5 and 6 are apparently modifying the code branch, and the pages branch, respectively, but doing so in separate local clones of the repo. I think there's a typo in code section 6, where I think he meant to start with
This doesn't seem like a situation where multiple local git repos are needed. What's wrong with managing both branches from one local repo?