Read Local Git Config
This feature allows you to read the local Git configuration of a repository. The code sample demonstrates how to use the gitconfiglocal package to read the .git/config file of a specified repository.
const gitconfiglocal = require('gitconfiglocal');
const path = require('path');
const repoPath = path.resolve('/path/to/repo');
gitconfiglocal(repoPath, (err, config) => {
if (err) throw err;
console.log(config);
});
Modify Local Git Config
This feature allows you to modify the local Git configuration of a repository. The code sample demonstrates how to read the .git/config file, modify the user name and email, and then write the changes back to the file.
const gitconfiglocal = require('gitconfiglocal');
const fs = require('fs');
const ini = require('ini');
const path = require('path');
const repoPath = path.resolve('/path/to/repo');
gitconfiglocal(repoPath, (err, config) => {
if (err) throw err;
config.user.name = 'New User';
config.user.email = 'newuser@example.com';
fs.writeFileSync(path.join(repoPath, '.git', 'config'), ini.stringify(config));
});