Githead is a lightweight Python utility library designed to retrieve the current Git commit hash (HEAD) of a repository. It provides a straightforward function to get this information, making it useful for embedding version data in applications or scripts. The library is currently at version 1.2.2 and is actively maintained, with updates released as needed for its focused functionality. It requires Python 3.9 or higher.
pip install githeadVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `githead` function to retrieve the current Git commit hash. The example includes robust error handling for environments that may not be within an initialized Git repository, creating a temporary one for demonstration purposes.
Ensure your Python script is executed within a directory that is part of a Git repository. You can initialize a new one with `git init` or navigate to an existing repository.
Always import explicitly with `from githead import githead` and refer to the PyPI page or GitHub repository (github.com/Zaczero/githead) for the correct Python library.
Run your script from within a Git repository. If you want to create a new one, use `git init` in your desired directory, then `git add .` and `git commit -m "Initial commit"` before using `githead`.
Install the library using pip: `pip install githead`.
Verify that Git is installed and configured correctly on your system (`git --version`). Ensure the repository has at least one commit (`git commit -m "Initial commit"`).