Skip to content

Instantly share code, notes, and snippets.

@walkerdepaula
Created October 1, 2020 17:57
Show Gist options
  • Save walkerdepaula/b4c092b2e1056363cb37ba171a4db443 to your computer and use it in GitHub Desktop.
Save walkerdepaula/b4c092b2e1056363cb37ba171a4db443 to your computer and use it in GitHub Desktop.

Revisions

  1. walkerdepaula created this gist Oct 1, 2020.
    14 changes: 14 additions & 0 deletions fetch-git-local-to-remote.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    **(requires bash or zsh, won't work with standard Bourne shell)**

    After pruning, you can get the list of remote branches with `git branch -r`. The list of branches with their remote tracking branch can be retrieved with `git branch -vv`. So using these two lists you can find the remote tracking branches that are not in the list of remotes.

    1:
    ```
    $ git fetch --prune
    ```

    2:
    ```
    $ git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
    ```