4

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.

6
  • Checked .git/packed-refs? Commented Oct 11, 2015 at 20:22
  • Not yet. Is it safe to edit this file manually? Commented Oct 11, 2015 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 Commented Oct 11, 2015 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? Commented Oct 11, 2015 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 :) Commented Oct 11, 2015 at 20:29

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.