def _generate_git_header(packagename, version, githash):
    """
    Generates a header to the version.py module that includes utilities for
    probing the git repository for updates (to the current git hash, etc.)
    These utilities should only be available in development versions, and not
    in release builds.

    If this fails for any reason an empty string is returned.
    """

    loader = pkgutil.get_loader(git_helpers)
    source = loader.get_source(git_helpers.__name__) or ''
    source_lines = source.splitlines()
    if not source_lines:
        log.warn('Cannot get source code for astropy_helpers.git_helpers; '
                 'git support disabled.')
        return ''

    idx = 0
    for idx, line in enumerate(source_lines):
        if line.startswith('# BEGIN'):
            break
    git_helpers_py = '\n'.join(source_lines[idx + 1:])

    verstr = version

    new_githash = git_helpers.get_git_devstr(sha=True, show_warning=False)

    if new_githash:
        githash = new_githash

    return _FROZEN_VERSION_PY_WITH_GIT_HEADER.format(
                git_helpers=git_helpers_py, packagename=packagename,
                verstr=verstr, githash=githash)