'Clone this repository.
:param target_path: Target path
:param mkdir: Create the target directory
:param bare: Whether to create a bare repository
:param origin: Base name for refs in target repository
cloned from this repository
:return: Created repository as `Repo`'

def clone(self, target_path, mkdir=True, bare=False, origin='origin'):

    if (not bare):
        target = self.init(target_path, mkdir=mkdir)
    else:
        target = self.init_bare(target_path, mkdir=mkdir)
    self.fetch(target)
    target.refs.import_refs(('refs/remotes/' + origin), self.refs.as_dict('refs/heads'))
    target.refs.import_refs('refs/tags', self.refs.as_dict('refs/tags'))
    try:
        target.refs.add_if_new(DEFAULT_REF, self.refs[DEFAULT_REF])
    except KeyError:
        pass
    target_config = target.get_config()
    encoded_path = self.path
    if (not isinstance(encoded_path, bytes)):
        encoded_path = encoded_path.encode(sys.getfilesystemencoding())
    target_config.set(('remote', 'origin'), 'url', encoded_path)
    target_config.set(('remote', 'origin'), 'fetch', '+refs/heads/*:refs/remotes/origin/*')
    target_config.write_to_path()
    (head_chain, head_sha) = self.refs.follow('HEAD')
    if (head_chain and (head_sha is not None)):
        target.refs.set_symbolic_ref('HEAD', head_chain[(-1)])
        target['HEAD'] = head_sha
        if (not bare):
            target.reset_index()
    return target
