3

I want to remove locally all branches that I can see with git branch -r. I've already removed all files from .git/refs/remote/*/ and appropriate records from .git/info/refs, but they are still there.

raacer
  • 5,302
  • 3
  • 27
  • 46
  • Checked `.git/packed-refs`? – MrTux Oct 11 '15 at 20:22
  • Not yet. Is it safe to edit this file manually? – raacer Oct 11 '15 at 20:24
  • 1
    Yeah, you can edit it manually (it's a simple text file with one or two lines for each ref), or call `git branch -r -D NAME`. Why do you want to delete them manually? - if those are deleted remotely you xan use `git fetch REMOTE --prune` – MrTux Oct 11 '15 at 20:25
  • I can see this is a plain text file, I'm just afraid this can break the repository somehow :) What about `git branch -D`, how do I remove the reference to a remote branch with this command, for example `refs/remotes/origin/develop`? – raacer Oct 11 '15 at 20:29
  • They are not deleted remotely, and I don't want to delete them remotely. I just want to cleanup my local tree view from those remote branches :) – raacer Oct 11 '15 at 20:29
  • So `git branch -r -D name` should do the trick, right? – raacer Oct 11 '15 at 20:32

1 Answers1

3

This command did the job:

git branch -r | xargs git branch -r -D

From the manual:

Use -r together with -d to delete remote-tracking branches. Note, that it only makes sense to delete remote-tracking branches if they no longer exist in the remote repository or if git fetch was configured not to fetch them again. See also the prune subcommand of git-remote(1) for a way to clean up all obsolete remote-tracking branches.

Thanks to @MrTux

raacer
  • 5,302
  • 3
  • 27
  • 46