HashMap<Nodeid, BranchChain> head2chain = new HashMap<Nodeid, BranchChain>();
while (!toQuery.isEmpty()) {
List<RemoteBranch> remoteBranches = remoteRepo.branches(new ArrayList<Nodeid>(toQuery)); //head, root, first parent, second parent
toQuery.clear();
while(!remoteBranches.isEmpty()) {
RemoteBranch rb = remoteBranches.remove(0);
BranchChain chainElement = head2chain.get(rb.head);
if (chainElement == null) {
chainElement = new BranchChain(rb.head);
// record this unknown branch to download later
branches2load.add(chainElement);