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?
Remove All Local Branches not on Remote First we get all remote branches using the git branch -r command. Next, we get the local branches not on the remote using the egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) command, Finally we delete the branches using the xargs git branch -d command.
In order to clean up remote tracking branches, meaning deleting references to non-existing remote branches, use the “git remote prune” command and specify the remote name. In order to find the name of your current configured remotes, run the “git remote” command with the “-v” option.
git fetch --prune is the best utility for cleaning outdated branches. It will connect to a shared remote repository remote and fetch all remote branch refs. It will then delete remote refs that are no longer in use on the remote repository.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With