Collection<VcsRef> (@NotNull Stream<? extends VcsRef> stream) { MultiMap<VirtualFile, VcsRef> map = MultiMap.create(); stream.forEach(ref -> map.putValue(ref.getRoot(), ref)); Stream<Collection<VcsRef>> groups = map.entrySet().stream().map(Map.Entry::getValue); return GitBranchUtil.collectCommon(groups, new NameAndTypeHashingStrategy()); }