Squash and merge master into same branch : <p>Is there a way to squash and merge master into the same branch? Effectively taking all the pending commits and putting them into 1 commit?</p>

<p>My original idea is a script that takes <code>my-branch</code> and does a <code>git checkout master &amp;&amp; git pull &amp;&amp; git checkout my-branch-squashed</code> and then  <code>git merge --squash my-branch</code> (deal with any merge conflicts) and then finally delete <code>my-branch</code> and rename <code>my-branch-squash</code> to <code>my-branch</code></p>

<p>This seem very round-about and possibly bad, so I am trying to see if there is any other way. The intent I am trying to solve is that when I put branches on github and they are "squashed and merged" into master, the branch that exists on the local machine doesn't match the branch that was merged into master, so when using <code>git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d;</code>  it doesnt correctly delete the branches that have already been merged into master.  What I want is a way to auto-delete old branches that have been merged into master</p>
