title: How to sync up my local git repo and delete branches that are gone in remote repo
body: <p>I have seen many somewhat similar stackoverflow questions regarding this.  I have tried many ways but am still stuck.</p>
  
  <p>I have a script like this:</p>
  
  <pre><code>git fetch --prune
  
  for k in $(git branch --merged| grep -E -v "(^\*|master|dev|release|origin)"); do
    if [ -z "$(git log -1 --since='38 week ago' -s "$k")" ]; then
      ## Info about the branches before deleting
      git log -1 --format="%ci %ce - %H $k" -s "$k";
      ## Delete from the remote
      # git push origin --delete "$k";
      ## Delete the local branch, regardless of whether it's been merged or not
      # git branch -D "$k"
    fi;
  done
  </code></pre>
  
  <p>I see:</p>
  
  <pre><code>host:folder user$ clean-up.sh 
  2018-05-18 14:46:25 -0700 gituser@company.com - 646766c885324b4f298d55604e0aabc2a00fdb58 feature/some-branch
  2018-05-16 19:56:56 -0400 gituser@company.com - 4e09733554eaf5e293ca7c668c19ec1395b361f9 some-other-branch
  </code></pre>
  
  <p>So it says these two following branches are to be deleted:</p>
  
  <pre><code>feature/some-branch
  some-other-branch
  </code></pre>
  
  <p>But they have actually been deleted from remote some time ago.  The problem is my local repo still have them.  I have tried many ways sync my local repo with the remote so that branches that are deleted from remote will also be deleted from local.</p>
  
  <p>Would anyone know of a good solution?</p>
  
  <p>An even better solution is to not depending on local repo at all and be able to clean up old branches in remote by purely depend on the remote repo.</p>
  
  <p>I have tried <strong>git remote prune origin</strong> but it didn't work</p>