GIT: remove remote branches with no local tracking branch

Let’s say that git branch -a outputs something like this:

  • A
  • B
  • C
  • *master
  • remotes/origin/A
  • remotes/origin/B
  • remotes/origin/C
  • remotes/origin/master
  • remotes/origin/X
  • remotes/origin/Y
  • remotes/origin/Z

In bold are those branches (X, Y, Z) that are in the remote repository but I have not checked them out yet and I don’t even intend to, they are related to a project I don’t participate in.

  • Does git branch -m have side effects for other developers?
  • Putting uncommitted changes at Master to a new branch by Git
  • Use TortoiseSVN to merge branch changes with the trunk
  • Git create a new branch with only a specified directory and its history then push to new repository
  • git branch naming best practices
  • Best strategy to distribute number into groups evenly
  • Is there a command to remove all remote branches (those that are saved on MY repository, not the actual remote branch in the remote) which do not have a local tracking branch?

    Edit: I intend to remove remote branches that are saved in my repository, showing the existence of the branch in the remote. I do not want to remove the actual branches in the remote.

    Edit 2: Clarification in comment to mattmilten

    You can recreate all remote branches with git pull, but I don’t always git pull.

    I often just git fetch origin master A B C and then merge or rebase or do anything I want with branches master, A, B or C.

    Point is, whenever I “git pull” (for some reason), all the branches I don’t want are created and it seems I have no simple option to remove them afterwards.

  • Git & Rails — I messed up, can i revert to last commit (delete model/controller/migrations/code)
  • Gitosis alternative?
  • Autocomplete issue while typing git stash show stash@{1}
  • How to remove a local Git repo from TortoiseGit?
  • Does git gets installed in IBM/AS400
  • What are the purpose of the bare git repositories in .repo/projects/ created by the Android repo script?
  • One Solution collect form web for “GIT: remove remote branches with no local tracking branch”

    No, this is not possible. The information about (all) branches is a part of your repo and will always be copied when a new clone is created. You need to ignore these branches or simply run git branch to list only your local branches.

    How would you be able to retrieve remote branches at a later time, if you delete the information about their existence?

    Git Baby is a git and github fan, let's start git clone.