def truncate_ref(ref):
    """Return bare branch, tag, or sha

    :param str ref: Full pathspec or short ref
    :return: Ref with 'refs/heads/' and 'refs/tags/' prefix removed
    :rtype: str
    """
    git_branch = 'refs/heads/'
    git_tag = 'refs/tags/'
    if ref.startswith(git_branch):
        length = len(git_branch)
    elif ref.startswith(git_tag):
        length = len(git_tag)
    else:
        length = 0
    return ref[length:]
