39

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

jszumski
  • 7,430
  • 11
  • 40
  • 53
Steven Byle
  • 13,149
  • 4
  • 45
  • 57

3 Answers3

59

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So I understand that as a `hook`, running these kinds of scripts can be a security threat. Running `prune` automatically after fetching would be my ideal solution. However, the root of my question is that the `prune` command already works with `Git` command line. So even if I could select to run it manually, that solves my issue. I do not see why EGit cannot implement the `prune` command. Do you know if EGit can do the pruning at all? – Steven Byle Mar 05 '13 at 14:26
  • 2
    @StevenByle see slide 10 of EGit 2.3 Review: https://bugs.eclipse.org/bugs/attachment.cgi?id=226938 . `prune` is not supported. – VonC Mar 05 '13 at 16:11
  • Exactly what I wanted to know. I appreciate your diligence :). – Steven Byle Mar 05 '13 at 16:17
  • there's a popup asking for key and value. set: key: "fetch.prune" (as mentioned); value = "true". don't forget to Team->fetch from upstream by right-clicking on your project for the change to take effect. – Joey Baruch May 02 '16 at 13:10
  • for some reason, the above also pruned my origin/master. Team->pull fixed it (i don't know why it did that). – Joey Baruch May 02 '16 at 13:14
  • 1
    @VonC i didn't see the 'prune' config value you are mentioning in your above screenshot – Andrew Norman May 04 '16 at 21:18
  • @AndrewNorman I agree. I said "the entry `fetch.prune` mentioned in `git config` *can* be added to your Egit configuration". It can, but the screenshot only represents one without that entry. – VonC May 04 '16 at 21:39
  • Like AndrewNorman said the screenshot is quite confusing. Stared at it for 1-2 minutes until I scrolled down into the comments and found out it has nothing to do with the solution. A screenshot with an example would be way more helpful. – hamena314 Aug 22 '16 at 08:39
  • 1
    @hamena314 Thank you for this feedback. I have updated the screenshot. – VonC Aug 22 '16 at 09:07
15

The recent EGit 3.3 release introduced prune support.

You can add a fetch.prune or a remote.<yourremotename>.prune key to the gitconfig and set it to true. When you fetch with EGit, this will automatically prune branches that are deleted on the central repository.

cheshire
  • 190
  • 2
  • 4
1

Setting fetch.prune = true in the git-Settings solves the problem. If you do it in the Repository Settings, you can differ this setting for each repository. If you want to use this setting for each repository, you better put fetch.prune = true in the User Settings. So you don't have to repeat it for each repository.

Joe.Hurke
  • 11
  • 3