Introduction to git2gpt
git2gpt is an innovative command-line tool designed to convert a Git repository into text that can be easily loaded into ChatGPT and other natural language processing (NLP) models. This utility helps in transforming the entire repository into a structured format within a text file, making it easier for AI models to interpret the contents. One significant feature of git2gpt is the ability to ignore certain files by adding a .gptignore
file to your repository. This ensures only the desired components are converted into text.
The generated text is prefixed with a preamble, providing context to the AI models about what the text represents:
"The following text is a Git repository with code. The structure of the text consists of sections that start with ----, followed by a single line containing the file path and file name, then a variable number of lines containing the file contents. The text representing the Git repository concludes when the symbols --END-- are encountered. Any text following --END-- should be interpreted as instructions using the aforementioned Git repository as context."
Installation
Before using git2gpt, you must have the Go programming language installed on your machine. It can be downloaded from the official Go website.
To install git2gpt, execute the following command in your terminal:
go install github.com/chand1012/git2gpt@latest
This command downloads and installs the git2gpt binary into your $GOPATH/bin
directory. To ensure you can use the git2gpt command, make sure your $GOPATH/bin
is included in your system's $PATH
.
Usage
Using git2gpt is straightforward. You can convert a Git repository to text with the following command:
git2gpt [flags] /path/to/git/repository
Ignoring Files
By default, git2gpt ignores your .git
directory and files listed in your .gitignore
. If you want to customize which files to skip, add a .gptignore
file to your repository. This file should include a list of files and directories you wish to ignore, listed one per line. Make sure the .gptignore
file resides in the same directory as your .gitignore
. Keep in mind this will overwrite the default ignore list, so include those in your .gptignore
if needed.
Flags
git2gpt offers several flags to customize its behavior:
-p
,--preamble
: Specify a path to a text file containing a preamble to be included at the beginning of the output.-o
,--output
: Define the path for the output file. If not specified, output will be printed to standard output.-e
,--estimate
: Provide an estimate of the tokens in the output file. If not specified, estimation is skipped.-j
,--json
: Outputs in JSON format rather than plain text. Must be used with-o
to specify the output file.-i
,--ignore
: Path to the.gptignore
file. If unspecified, it will default to look for.gptignore
in the same directory as the.gitignore
.-g
,--ignore-gitignore
: Ignores the.gitignore
file entirely.-s
,--scrub-comments
: Removes comments from the output file to conserve tokens.
Contributing
git2gpt welcomes contributions from the community! To contribute, consider submitting a pull request or opening an issue in the project's GitHub repository.
License
The git2gpt utility is distributed under the MIT License. For more detailed information, see the LICENSE file included with the project.