Overview
useGit provides two ways to work with Git repositories:- Default instance - A pre-configured instance ready to use immediately
- Custom instances - Create multiple instances with custom configurations
Default Git Instance
The simplest way to use useGit is with the default exported instance:- Working directory:
"." - Debug mode:
false
Creating Custom Instances
UsecreateGit() to create custom instances with specific configurations:
Configuration Options
ThecreateGit() function accepts a configuration object with the following properties:
The working directory for Git operations. All commands will execute in this directory.
Enable debug logging to see Git commands as they execute. Logs are written to stdout/stderr.
Type Signature
Multiple Repository Support
Create separate instances to work with multiple repositories simultaneously:Debug Mode
Enable debug mode to troubleshoot issues or understand what Git commands are being executed:Debug mode sets
process.env.DEBUG = "true" and outputs formatted logs with colored labels to help identify command execution.Best Practices
Single Repository Projects
For projects working with a single repository, use the default instance:Multi-Repository Projects
For monorepos or tools managing multiple repositories, create named instances:Development vs Production
Use environment variables to control debug mode:Instance Lifecycle
Each Git instance is independent and lightweight. You don’t need to explicitly close or dispose of instances:Next Steps
Working Directory
Learn how working directories are managed
Error Handling
Handle errors and failures gracefully