README
¶
local-gitingest
local-gitingest is a command-line tool written in Go that converts a local Git repository into a single text file. This text file includes the repository's directory structure and the contents of its source files (excluding specified file types and those exceeding a size limit). This format is suitable for providing context to large language models (LLMs) or for creating quick project snapshots. It's inspired by the online tool gitingest.com.
Features
- Directory Structure: Generates a hierarchical representation of your project's directory structure.
- File Content Inclusion: Includes the content of text-based source files.
- Exclusion Filters:
- Default Exclusions: Automatically excludes executable files (files without extensions) and common directories like
.git,node_modules, andvendor. .gitignoreSupport: Automatically respects.gitignorepatterns from your repository root.- Extension-based Exclusion: Allows you to specify file extensions to exclude (e.g.,
.jpg,.png,.log). - Directory-based Exclusion: Allows you to exclude specific directories at the root level.
- Default Exclusions: Automatically excludes executable files (files without extensions) and common directories like
- Target Subdirectory: Optionally ingest only a specific subdirectory instead of the entire repository.
- File Size Limit: Optionally limits the size of files included in the output.
- Verbose Mode: Optional verbose output (
-v) shows which files are being excluded. - Git Repository Root Check: Ensures the tool is run from the root directory of a Git repository.
Installation
-
Make sure you have Go installed (version 1.16 or later).
-
Use go install:
$go install github.com/bigwhite/local-gitingest@latestor
Build the executable from source:
$git clone https://github.com/bigwhite/local-gitingest.git $cd local-gitingest $make
Usage
local-gitingest [options] [target-subdirectory]
Options:
-d <directory>: Target subdirectory to ingest. Only this directory (recursively) will be included in the output. If not specified, the entire repository is processed.-exclude-dir <dir>: Directories to exclude at the root level (can be specified multiple times). For example,-exclude-dir=vendor -exclude-dir=node_modules.-exclude <extensions>: A comma-separated list of file extensions to exclude (e.g.,.jpg,.png,.gif). Do not include a space after the comma.-o <filename>: Specifies the output file name (default:output.txt).-size-limit: Enables a file size limit.-max-size <bytes>: Sets the maximum file size in bytes (default: 50KB, which is 51200 bytes). This option is only used if-size-limitis also provided.-v, -verbose: Enables verbose mode, showing files excluded by filters.
Arguments:
target-subdirectory: Alternative to-dflag. Specifies the subdirectory to ingest.
Important: local-gitingest must be run from the root directory of a Git repository.
Examples
-
Basic Usage (default exclusions):
./local-gitingestThis will create a file named
output.txtcontaining the repository structure and file contents, excluding executables and common build/dependency directories. -
Target a specific subdirectory:
./local-gitingest integration-testsor
./local-gitingest -d integration-testsThis will only ingest files from the
integration-testsdirectory. -
Exclude specific directories:
./local-gitingest -exclude-dir=vendor -exclude-dir=node_modulesThis will exclude the
vendorandnode_modulesdirectories from the output. -
Combine target subdirectory with extension filter:
./local-gitingest -d cmd/server -exclude go,sumThis will only ingest files from the
cmd/serverdirectory, excluding.goand.sumfiles. -
Exclude specific file types:
./local-gitingest -exclude .log,.tmp,.bakThis will exclude files with the extensions
.log,.tmp, and.bak. -
Specify output file and enable size limit:
./local-gitingest -o my_repo.txt -size-limit -max-size 102400This will create a file named
my_repo.txt, and only files smaller than 100KB (102400 bytes) will be included. -
Exclude specific file types and enable size limit:
./local-gitingest -exclude .log,.tmp,.bak -o my_repo.txt -size-limit -max-size 102400This will create a file named
my_repo.txt, exclude files with the extensions.log,.tmp, and.bak. and only files smaller than 100KB (102400 bytes) will be included. -
Verbose mode (shows excluded files):
./local-gitingest -vThis will show which files are being excluded by
.gitignorepatterns. -
.gitignoresupport: The tool automatically respects your repository's.gitignorefile. Patterns like*.log,build/,*.tmpwill exclude matching files and directories from the output.
Why use local-gitingest?
- LLM Context: Provide a concise representation of your codebase to large language models for tasks like code completion, documentation generation, or code analysis.
- Project Snapshots: Quickly create a text-based snapshot of your project at a specific point in time.
- Offline usage: Unlike gitingest.com, local-gitingest can be used offline.
Documentation
¶
There is no documentation for this package.