git-config-parser
v1.0.0
Published
Parse .git/config file into JavaScript object - minimal, zero dependencies
Readme
git-config-parser
Parse .git/config files into JavaScript objects. Zero dependencies, minimal footprint.
Installation
npm install git-config-parserUsage
Sync
import { parseSync } from "git-config-parser";
// Parse current repo's .git/config (from cwd)
const config = parseSync();
// Or pass a custom path
const config = parseSync("/path/to/.git/config");Async
import { parse } from "git-config-parser";
// Parse current repo's .git/config
const config = await parse();
// Or pass a custom path
const config = await parse("/path/to/some/config");Output Shape
The parser returns a nested object matching the Git config structure:
{
core: {
repositoryformatversion: "0",
filemode: "true",
bare: "false"
},
remote: {
origin: {
url: "https://github.com/user/repo.git",
fetch: "+refs/heads/*:refs/remotes/origin/*"
}
},
branch: {
main: {
remote: "origin",
merge: "refs/heads/main"
}
}
}Keys that appear multiple times in the same section are returned as arrays.
API
| Function | Signature | Description |
| ------------ | ---------------------------------------------- | ----------------------------------------- |
| parseSync | (configPath?: string) => object | Parse config synchronously |
| parse | (configPath?: string) => Promise<object> | Parse config asynchronously |
- configPath (optional): Path to the config file. If omitted, the parser looks for
.git/configby walking up fromprocess.cwd().
Testing Locally
Clone the repo and install dependencies (none required for the module itself):
cd git-config-parser npm installRun tests:
npm testTry it with a quick script:
node -e "import('./index.js').then(m => console.log(m.parseSync('./fixtures/sample-config')))"Or from inside a git repo (parses
.git/configfrom cwd):node -e "import('./index.js').then(m => console.log(m.parseSync()))"Link the package for local testing in another project:
npm link cd /path/to/your-project npm link git-config-parserThen use it in your project as usual.
Contributing
Contributions are welcome. Anyone can contribute.
- Open an issue to discuss changes or report bugs
- Submit pull requests for fixes or new features
- Ensure tests pass with
npm testbefore submitting
License
MIT
