title: git: keeping repos in sync despite chopped history
body: <p>Background: I'm in the process of cleaning up a project before releasing it as open-source. During the code history there's been a bunch of things I don't really want to show up in a public repository (swearing in comments, hardcoded paths, embarrassing pieces of code), so I only want the public to see the code base after the cleanup cut-off point -  yet I want to retain full history in my own private repository.</p>
  
  <p>After the cutoff point the private and public repositories are going to be kept entirely in sync. Apart from local non-pushed temporary branches, there won't be any private branches; the master branch on both repositories should be identical, except the public history is chopped at the cut-off point.</p>
  
  <p>As far as I can tell Git requires repositories having full history, so I can't <em>directly</em> push my local master branch to both the public and private repositories. I guess it would be possible creating a separate 'public' branch and using history rewriting, but this would require merging the private branch to the public before pushing code to the repositories - I'd like a setup that requires as little manual work as possible.</p>
  
  <p>The public repository is intended to be pull-only, with me doing integration. The private repository will be hosted on my own linux server, so it would be possible to set up commit hooks that auto-merge to a different (public) repo and then push to the public repo. I hope there's a cleaner solution, though - there's probably a way to structure this that I haven't thought of.</p>
  
  <p>Thanks in advance for any suggestions :)</p>
  
  <h2>Update 1</h2>
  
  <p>Trying to follow VonC's recommendation, this is what I've got so far:</p>
  
  <p>Assumptions:
  Private repository is cleaned up, committed locally, and pushed to git@server:private.git .
  Public repository created with files from last private commit, is committed locally, and pushed to git@server:public.git .</p>
  
  <p>1) <code>~/priv$ git remote add public git@server:public.git</code>
  2) <code>~/priv$ git fetch public</code></p>
  
  <blockquote>
    <p>warning: no common commits
    (stuff snipped)
    * [new branch]      master     -> public/master</p>
  </blockquote>
  
  <p>3) <code>~/priv$ git log --format='%H %s'</code></p>
  
  <blockquote>
    <p>d2d66cf2861ac7136ee3dc04467781825413b084 Cleaned up code base, ready for public!
    9ba0ccf4c819eb85dbe4613caec959b04edfb39a Commit #2
    a37c3c645dcdc4d8e5fc7ef3c53727cbf1d903ad First (private) commit.</p>
  </blockquote>
  
  <p>The top hash (d2d66...) is the private head commit.</p>
  
  <p>4) <code>~/priv$ git log --reverse --format='%H %s' public/master</code></p>
  
  <blockquote>
    <p>090a335746ecb03ea5362909be4969b87a99ab80 First public commit!
    c43fccdda05319e57498f4f517650f9edbdb942a Second public commit :)</p>
  </blockquote>
  
  <p>Because of --reverse, the oldest hash (090a3...) is at top.</p>
  
  <p>5) <code>~/priv$ echo '090a335746ecb03ea5362909be4969b87a99ab80 d2d66cf2861ac7136ee3dc04467781825413b084' &gt;&gt; .git/info/grafts</code></p>
  
  <p>At this point, <code>git log public/master</code> shows revisionist history, but I'm unsure how to progress wrt. filter-branch and all that... I've only succeeded in messing things up :)</p>