title: Git: How to push only tracked files to remote
body: <p>I've seen many variants of this question on SO but none of them had what I looking for. Say I have a repo <code>~/MyRepo/</code>:</p>
  
  <pre><code>$ ls -a ~/MyRepo
  code.r junk.txt .git
  </code></pre>
  
  <p>In <code>MyRepo</code> only the file <code>code.r</code> is being tracked, and <code>junk.txt</code> is not tracked. 
  And say I have a remote (e.g. on Dropbox) at <code>~/Dropbox/MyShare/</code> that a friend has access to (only for reading). The intent is for this remote to only contain my <em>latest committed version</em> of <code>code.r</code>, and <em>not</em> contain <code>junk.txt</code>. I'm trying to achieve the following: whenever I <em>commit</em> <code>code.r</code> I want to be able to update (automatically if possible) the remote <code>~/Dropbox/MyShare/code.r</code> with the committed version of <code>~/MyRepo/code.r</code>. </p>
  
  <p>I am aware of <code>.gitignore</code> but not interested in that route because I have several untracked files that I want to ignore, and I only want to "push" the files I'm tracking to the remote. 
  I also tried the approach of doing a <code>cloning</code> into <code>~/Dropbox/MyShare/</code> but cloning or pulling always seem to include <em>tracked</em> and <em>untracked</em> files, thus polluting my Remote. </p>
  
  <p>My current solution is to have a post-commit hook under <code>~/MyRepo/.git/hooks/</code> that has explicit commands to individually copy all the "files I care about" to the remote. I don't like this solution because the "files I care about" can change, and I don't have to go and update the post-commit hook. </p>
  
  <p>I am hoping there is a way to automatically make the last-committed versions available in <code>~/Dropbox/MyShare/</code> by some combination of git commands. I don't mind doing a single manual "push" command every time I commit in <code>~/MyRepo/</code>. </p>
  
  <p>Here is what I tried based on one of the answers below, but I am still stumped.</p>
  
  <pre><code># create my repo
  mkdir foo
  cd foo
  git init
  touch fileA fileB fileC
  git add fileA
  git commit -m 'new'
  
  # now create remote 
  mkdir ../foo_remote
  cd ../foo_remote
  git init
  cd ../foo
  git remote add foo_remote ../foo_remote
  
  bash-3.2$ git remote -v                                                                                                                                                                                                                                                         
  foo_remote      ../foo_remote (fetch)                                                                                                                                                                                                                                           
  foo_remote      ../foo_remote (push)                                                                                                                                                                                                                                            
  </code></pre>
  
  <p>Now when I try to push, I get this mean error message:</p>
  
  <pre><code>bash-3.2$ git push foo_remote master                                                                                                                                                                                                                                            
  
  Counting objects: 3, done.                                                                                                                                                                                                                                                      
  Writing objects: 100% (3/3), 207 bytes, done.                                                                                                                                                                                                                                   
  Total 3 (delta 0), reused 0 (delta 0)                                                                                                                                                                                                                                           
  Unpacking objects: 100% (3/3), done.                                                                                                                                                                                                                                            
  remote: error: refusing to update checked out branch: refs/heads/master                                                                                                                                                                                                         
  remote: error: By default, updating the current branch in a non-bare repository                                                                                                                                                                                                 
  remote: error: is denied, because it will make the index and work tree inconsistent                                                                                                                                                                                             
  remote: error: with what you pushed, and will require 'git reset --hard' to match                                                                                                                                                                                               
  remote: error: the work tree to HEAD.                                                                                                                                                                                                                                           
  remote: error:                                                                                                                                                                                                                                                                  
  remote: error: You can set 'receive.denyCurrentBranch' configuration variable to                                                                                                                                                                                                
  remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into                                                                                                                                                                                                
  remote: error: its current branch; however, this is not recommended unless you                                                                                                                                                                                                  
  remote: error: arranged to update its work tree to match what you pushed in some                                                                                                                                                                                                
  remote: error: other way.                                                                                                                                                                                                                                                       
  remote: error:                                                                                                                                                                                                                                                                  
  remote: error: To squelch this message and still keep the default behaviour, set                                                                                                                                                                                                
  remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.                                                                                                                                                                                                  
  To ../foo_remote                                                                                                                                                                                                                                                                
   ! [remote rejected] master -&gt; master (branch is currently checked out)                                                                                                                                                                                                         
  error: failed to push some refs to '../foo_remote'           
  </code></pre>
  
  <p>Any ideas where I'm going wrong? </p>