I created a fork of a git repo on BitBucket (let's call it fork_origin
). Now the upstream repository (let's call it upstream_origin
) has had numerous branches merged into it's master and deleted. So running
git fetch --prune upstream_origin
deleted lots of remote/upstream_origin/
branches, but now those same branches still exist in the remote/fork_origin/
namespace.
Is there a standard git command to deal with this? I'd like to stay away from complex bash scripts that do mass deletes on the remote repos.
UPDATE:
As suggested, I tried to use the remote prune command:
git remote prune fork_origin
However, it had no effect. Upon further investigation, that seems to work only for 'stale' branches, but when I run:
git remote show fork_origin
it shows that all of the branches are still 'tracked'. So it makes sense that the git remote prune
command had nothing stale to delete. Is there a way to force the remote repo (fork_origin
) to update it's branch statuses relative to upstream_origin
?
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 delete the unneeded branches which came from upstream repository, it is totally safe as you rebase you forked repo with upstream repo later as well.
The easiest way to delete local Git branches is to use the “git branch” command with the “-d” option. The “-d” option stands for “–delete” and it can be used whenever the branch you want to clean up is completely merged with your upstream branch. $ git branch -d release Deleted branch feature (was bd6903f).
Run git fetch -p (to remove any deleted remote branches). Run our custom command (to remove local branches with a deleted remote branch).
If you want to remove the branches on the remote use this command:
git remote prune fork_origin
But before that, take a look at this thread and see what can go wrong: git remote prune – didn't show as many pruned branches as I expected
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