We use a subtree deployment a lá this Gist to deploy a subdirectory of our Yeoman project. In our case, the branch is called production, not gh-pages.
There is actually a solution that is much more simple.
Source: https://gist.github.com/cobyism/4730490#gistcomment-2337463
$ rm -rf dist
$ echo "dist/" >> .gitignore
$ git worktree add dist gh-pages
$ make # or what ever you run to populate dist
$ cd dist
$ git add --all
$ git commit -m "$(git log '--format=format:%H' master -1)"
$ git push origin production --force
$ cd ..
The trick was to chain the subtree split into a forced push:
git push origin `git subtree split --prefix dist master`:production --force
I got this from the Addendum of http://clontz.org/blog/2014/05/08/git-subtree-push-for-deployment/, who actually references this answer on Stack Overflow. I had skimmed this one earlier but Steve Clontz's post made it click for me.
cd dist
git init
git add .
git commit -am "deploy"
git push --force <remote URL> master
rm -rf .git
cd ..
This creates a new git repository in the subdirectory you specify and force pushes everything from there.
I've just enhanced the answer of ele adding generic expressions <>
to make it more clear:
git push <remote> `git subtree split --prefix <local-folder> <remote-branch>`:<remote-branch> --force
Example values
<remote>
origin
other-origin-name
https://github.com/full-url/of-repo
<local-folder>
Local folder relative to repo root (execute this command in root), e.g.: /dist
<remote-branch>
master
any-other-branchname