12

Is there a handy way to get my local git repo to forget about remote branches that have been deleted? git svn fetch doesn't "re-sync everything" like I hoped it might. My local repo was set up with using an import of the standard svn repo layout (git svn -s …).

related: Why does git remote not list anything on my git-svn repo?

Community
  • 1
  • 1
John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • My first thought would be to just delete the files representing those branches, which are just little text files in `.git/refs/remotes`. But there's probably a more correct way than that, and I'm sure it would be possible to mess things up if you go poking around in the `.git` folder without really knowing what you're doing. – Tyler Dec 09 '10 at 08:53
  • You'd also want to look at your `.git/config` file and delete any mention of them there. – Tyler Dec 22 '10 at 17:07

2 Answers2

15

You can remove orphaned remote branches by executing the following commands:

git branch -d -r my_branch
rm -rf .git/svn/refs/remotes/my_branch

To remove all orphaned branches at once rather than one at a time, see the answer here.

Community
  • 1
  • 1
Matt Hulse
  • 5,496
  • 4
  • 29
  • 37
  • I also had to do `rm .git/refs/remotes/origin/my_branch` for the branch not to be shown. Also, `rm -rf .git/svn/refs/remotes/origin/my_branch/` instead of `rm -rf .git/svn/refs/remotes/my_branch/` (note the `origin`). Any idea why? – Miguel Prada Sep 26 '16 at 13:05
  • To answer myself about the difference, I probably used `--prefix` when cloning, which is default behaviour from 2.0 onwards. – Miguel Prada Sep 26 '16 at 13:11
0

On the first thought, I would suggest trying git remote prune. Excerpt from documentation:

prune

Deletes all stale remote-tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in "remotes/".

With --dry-run option, report what branches will be pruned, but do not actually prune them.

I think this should also work with a remote called svn...

eckes
  • 64,417
  • 29
  • 168
  • 201
  • 1
    nope… git-svn doesn't store remotes in the standard way, and not in a handy abstraction of it either… there are no remotes, `git remote` has no output. – John Bachir Dec 28 '10 at 01:19
  • Although this does not work, it is relevant information to know that it doesn't – Nebula May 13 '22 at 04:53