Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EGit: Pruning Remote Tracking Branches that have been Deleted on the Remote Repo

I'm using EGit (for Eclipse) with a team of devs. We have been creating a lot of feature and fix branches for new work, and then merging them into our release branches when they are completed. Right after they are merged into the correct release branch, these temporary branches are usually deleted to keep our remote repo clean.

I'm noticing that when these branches get deleted, I will fetch from our remote repo, but EGit doesn't remove them from my remote tracking view. My remote tracking view will still show deleted branches that are no longer on the remote repo (and there is no indication that they have been deleted). The only way (I have found) to have my remote tracking view reflect the actual repo is to delete all of my remote tracking branches manually (highlight and delete), and then fetch them again. This seems very roundabout, especially since you can prune remote branches via command line, like this:

git remote prune origin

Basically, what I would like to know is if there is a way to configure/make EGit perform this pruning when remote tracking branches change (after I fetch). Here is my current fetch configuration on my origin remote:

enter image description here

like image 565
Steven Byle Avatar asked Mar 04 '13 20:03

Steven Byle


People also ask

Does git prune delete remote 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.

How remove deleted branch from remote?

Steps to delete remote Git branchesIssue the git push origin –delete branch-name command, or use the vendor's online UI to perform a branch deletion. After the remote branch is deleted, then delete the remote tracking branch with the git fetch origin –prune command.

What happens when you delete a remote branch?

Pushing to delete remote branches also removes remote-tracking branches. Note that deleting the remote branch X from the command line using a git push will also remove the local remote-tracking branch origin/X , so it is not necessary to prune the obsolete remote-tracking branch with git fetch --prune or git fetch -p .

How do you clean remote branches?

In order to clean up remote-tracking branches while fetching, use the “git fetch” command with the “–prune” option. Alternatively, you can simply use the “-p” shortcut instead of typing “prune” every time.

Is there a way to prune remote branches via Egit?

This seems very roundabout, especially since you can prune remote branches via command line, like this: git remote prune origin Basically, what I would like to know is if there is a way to configure/make EGit perform this pruning when remote tracking branches change (after I fetch).

Does Egit perform branch pruning after each fetch?

Original answer (March 2013) EGit perform this pruning when remote tracking branches change (after I fetch). Not that I know of. More generally, perform any action after each fetch on the client side is not possible with hooks.

Why does Egit remove temporary branches from remote tracking?

Right after they are merged into the correct releasebranch, these temporary branches are usually deleted to keep our remote repo clean. I'm noticing that when these branches get deleted, I will fetch from our remote repo, but EGit doesn't remove them from my remote tracking view.

How to delete remote tracking branches in Git?

You can use the prune subcommand of git-remote for cleaning obsolete remote-tracking branches. Alternatively, you can use the get-fetch command with the --prune option to remove any remote-tracking references that no longer exist on the remote. That’s all about deleting remote-tracking branches in Git.


1 Answers

Update March 2014: As mentioned by cheshire's answer, EGit 3.3 added that prune feature.

You can see said feature introduced in this Gerrit code review in JGit (and tested here)

The entry fetch.prune mentioned in git config can be added to your Egit configuration:

https://wiki.eclipse.org/images/f/f8/RepositoryConfigurationSettings.png


Original answer (March 2013)

EGit perform this pruning when remote tracking branches change (after I fetch).

Not that I know of.

More generally, perform any action after each fetch on the client side is not possible with hooks.
It has been requested, and was at one point implemented on the server side only: hook post-upload (run after a fetch), but removed, for security reason in a multi-user environment.

like image 110
VonC Avatar answered Sep 28 '22 19:09

VonC