def fetch_all(source_repo, target_repo, remote_name=None): """Fetch branches and tags from a remote repository Unlike :code:`git fetch`, this will also update local branches to point at the same commit as their remote counterpart. Parameters ---------- source_repo : dulwich.repo.Repo target_repo : dulwich.repo.Repo remote_name : str """ if remote_name is None: remote_name = 'origin' refs = LocalGitClient().fetch(source_repo.path, target_repo) for key, value in refs.items(): remote_key = key.replace( b'heads', b'remotes/%s' % bytes(remote_name, encoding='UTF-8')) target_repo.refs[remote_key] = value target_repo[key] = value