Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pruning branches that were deleted in upstream Git repo but still exist in my fork

Tags:

git

bitbucket

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?

like image 547
Peter Groves Avatar asked May 03 '13 21:05

Peter Groves


People also ask

Does git prune deleted branches?

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.

Can I delete branches from a forked repo?

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.

How do you get rid of stale branches?

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).

How remove deleted branch from remote?

Run git fetch -p (to remove any deleted remote branches). Run our custom command (to remove local branches with a deleted remote branch).


1 Answers

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

like image 128
Daniel Gomes Avatar answered Oct 14 '22 14:10

Daniel Gomes