title: How to add a git repo as a submodule of itself? (Or: How to generate GitHub Pages programmatically?)
body: <p>I want to start using <a href="http://pages.github.com/" rel="noreferrer">GitHub Pages</a> for my project's website. This simply requires a branch (subtree) named <code>gh-pages</code> in the repo, and serves up its content. The problem is that part of the website (manual, changelog, download page...) is auto-generated by the build system, so I want to find the best way to commit these changes to the <code>gh-pages</code> branch while the main repo remains on <code>master</code> (or wherever).</p>
  
  <p>To commit to the <code>gh-pages</code> branch, I could write a script that clones the repo into a temporary directory, makes the modifications, commits them, and then pushes them back to the main repo. But this sounds like an error-prone process, so I'm hoping there is an easier way.</p>
  
  <p>A friend suggested that I might add the <code>gh-pages</code> branch as a submodule to the main repository. I ran a little experiment, but it doesn't quite work:</p>
  
  <pre><code>$ git init main
  Initialized empty Git repository in /tmp/main/.git/
  $ cd main
  $ touch main.txt
  $ git add .
  $ git commit -m'Initial commit in main branch.'
  [master (root-commit) 1c52a4e] Initial commit in main branch.
   0 files changed, 0 insertions(+), 0 deletions(-)
   create mode 100644 main.txt
  $ git symbolic-ref HEAD refs/heads/gh-pages
  $ rm .git/index
  $ git clean -fdx
  Removing main.txt
  $ touch index.html
  $ git add .
  $ git commit -m'Initial commit in website branch.'
  [gh-pages (root-commit) 94b10f2] Initial commit in website branch.
   0 files changed, 0 insertions(+), 0 deletions(-)
   create mode 100644 index.html
  $ git checkout master
  Switched to branch 'master'
  $ git submodule add -b gh-pages . gh-pages
  repo URL: '.' must be absolute or begin with ./|../
  $ git submodule add -b gh-pages ./ gh-pages
  remote (origin) does not have a url defined in .git/config
  </code></pre>
  
  <p>I'm new to submodules; have done some reading, of course, but I don't understand this behaviour. Why does it need an <code>origin</code> remote? Ideally, I want the submodule to always reference the repo that it resides in, so it should not reference <code>origin</code> or any other remotes. If somebody clones the repo and runs <code>git submodule init ; git submodule update</code>, it should ideally pull from the newly cloned repo.</p>
  
  <p>Is it possible to add a repo as a submodule of itself? Is it desirable? Are there any pitfalls that I need to be aware of? Is there a better way to achieve what I want?</p>