title: Non-destructive Git checkout in dirty work tree ($HOME/.dotfiles)
body: <p>This problem came up while scheming up another Git <code>.dotfiles</code> management system. I want to use <code>$HOME</code> as my working tree and have the repository stored elsewhere (not under <code>.git</code> as that confuses other repositories).</p>
  
  <p>On old machines with previously copied and potentially tweaked dotfiles, I'd now like to clone my new dotfiles repository and (<em>wave hands</em>) get to a state where I can see the (pre-)existing state of my <code>$HOME/.*</code> dotfiles as modifications to the master of my newly cloned repository. This is mostly background, in <strong>Git I just want to cautiously checkout in a dirty directory without overwriting</strong>.</p>
  
  <p>(In an ordinary case I could just start in a new directory and then copy in my changes, but that seems hard to do when the work-tree is my <code>$HOME</code>.)</p>
  
  <p>I found one pair of commands that seems to get me to the right place, but I'm
  not sure if there are either pitfalls to this approach or simpler ways to do
  the same thing:</p>
  
  <pre><code>git read-tree -v HEAD # load HEAD into the index
  git checkout-index -a # cautiously check out all files without overwriting
  </code></pre>
  
  <p>Do these two commands get to the same state as copying away my home, doing an ordinary checkout, then copying back my files, such that <code>git diff</code> would have just the changes I'd done on this machine and no files deleted?</p>
  
  <p>Are there other options to these that should be applied?</p>
  
  <p>The context is my (alpha) bootstrap script:</p>
  
  <pre><code>git clone --bare -n git://github.com/$(git config github.user)/.dotfiles.git ~/.dotfiles/repo.git
  git config -f .dotfiles/repo.git/config core.bare false
  git config -f .dotfiles/repo.git/config core.logallrefupdates true
  git config -f .dotfiles/repo.git/config core.worktree $HOME
  export GIT_DIR=~/.dotfiles/repo.git ;  export GIT_WORK_TREE=~
  git read-tree -v HEAD 
  git checkout-index -a # all files without overwriting
  ln -sf $HOME/.dotfiles/gitignore-dots $HOME/.dotfiles/repo.git/info/exclude
  </code></pre>