# Buggy code
def _checkout_default_branch(self):
    # switch to default branch
    git_repo = self.scm.repo
    origin_refs = git_repo.remotes["origin"].refs
    ref = origin_refs["HEAD"].reference
    branch_name = ref.name.split("/")[-1]
    if branch_name in git_repo.heads:
        branch = git_repo.heads[branch_name]
    else:
        branch = git_repo.create_head(branch_name, ref)
        branch.set_tracking_branch(ref)
    branch.checkout()


# Traceback (AttributeError)
2020-09-21 16:46:48,685 DEBUG: Check for update is enabled.
2020-09-21 16:46:48,686 DEBUG: assuming default target 'dvc.yaml'.
2020-09-21 16:46:48,687 DEBUG: fetched: [(3,)]
2020-09-21 16:46:48,720 DEBUG: fetched: [(68,)]
2020-09-21 16:46:48,728 ERROR: unexpected error - No item found with id 'origin/HEAD': 'IterableList' object has no attribute 'origin/HEAD'
------------------------------------------------------------
Traceback (most recent call last):
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/git/util.py", line 881, in __getitem__
return getattr(self, index)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/git/util.py", line 874, in __getattr__
return list.__getattribute__(self, attr)
AttributeError: 'IterableList' object has no attribute 'origin/HEAD'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/main.py", line 76, in main
ret = cmd.run()
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/command/repro.py", line 47, in run
params=self.args.params,
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/__init__.py", line 51, in wrapper
return f(repo, *args, **kwargs)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/scm_context.py", line 4, in run
result = method(repo, *args, **kw)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/reproduce.py", line 89, in reproduce
**kwargs,
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/reproduce.py", line 151, in _reproduce_experiments
return repo.experiments.reproduce_one(**kwargs)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 274, in reproduce_one
stash_rev = self.new(**kwargs)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 36, in wrapper
return f(exp, *args, **kwargs)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 306, in new
self._scm_checkout(rev)
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 168, in _scm_checkout
self._checkout_default_branch()
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 178, in _checkout_default_branch
ref = origin_refs["HEAD"].reference
File "/home/roman/miniconda3/envs/tensorflow/lib/python3.6/site-packages/git/util.py", line 883, in __getitem__
raise IndexError("No item found with id %r" % (self._prefix + index)) from e
IndexError: No item found with id 'origin/HEAD'

# Fixed code
def _checkout_default_branch(self):
    from git.refs.symbolic import SymbolicReference

    # switch to default branch
    git_repo = self.scm.repo
    origin_refs = git_repo.remotes["origin"].refs

    # origin/HEAD will point to tip of the default branch unless we
    # initially cloned a repo that was in a detached-HEAD state.
    #
    # If we are currently detached because we cloned a detached
    # repo, we can't actually tell what branch should be considered
    # default, so we just fall back to the first available reference.
    if "HEAD" in origin_refs:
        ref = origin_refs["HEAD"].reference
    else:
        ref = origin_refs[0]
        if not isinstance(ref, SymbolicReference):
            ref = ref.reference
    branch_name = ref.name.split("/")[-1]

    if branch_name in git_repo.heads:
        branch = git_repo.heads[branch_name]
    else:
        branch = git_repo.create_head(branch_name, ref)
        branch.set_tracking_branch(ref)
    branch.checkout()