A pure JavaScript implementation of git for node and browsers
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Reading and writing Git configuration values.
Retrieves a configuration value from Git config.
/**
* Get a configuration value
* @param args.fs - File system client
* @param args.dir - Working tree directory path
* @param args.gitdir - Git directory path
* @param args.path - Configuration key path (e.g., 'user.name')
* @returns Promise resolving to configuration value
*/
function getConfig(args: {
fs: FsClient;
dir?: string;
gitdir?: string;
path: string;
}): Promise<any>;Usage Examples:
import git from "isomorphic-git";
import fs from "fs";
// Get user name
const userName = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "user.name"
});
console.log("User name:", userName);
// Get user email
const userEmail = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "user.email"
});
console.log("User email:", userEmail);
// Get remote URL
const remoteUrl = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.url"
});
console.log("Origin URL:", remoteUrl);
// Get core configuration
const autocrlf = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "core.autocrlf"
});
console.log("Auto CRLF:", autocrlf);Retrieves all values for a configuration key that can have multiple values.
/**
* Get all values for a configuration key
* @param args.fs - File system client
* @param args.dir - Working tree directory path
* @param args.gitdir - Git directory path
* @param args.path - Configuration key path
* @returns Promise resolving to array of all values
*/
function getConfigAll(args: {
fs: FsClient;
dir?: string;
gitdir?: string;
path: string;
}): Promise<any[]>;Usage Example:
import git from "isomorphic-git";
import fs from "fs";
// Get all remote URLs (useful for multi-URL remotes)
const allUrls = await git.getConfigAll({
fs,
dir: "/path/to/repo",
path: "remote.origin.url"
});
console.log("All origin URLs:", allUrls);
// Get all submodule paths
const submodules = await git.getConfigAll({
fs,
dir: "/path/to/repo",
path: "submodule.*.path"
});
console.log("Submodule paths:", submodules);Sets a configuration value in Git config.
/**
* Set a configuration value
* @param args.fs - File system client
* @param args.dir - Working tree directory path
* @param args.gitdir - Git directory path
* @param args.path - Configuration key path
* @param args.value - Value to set
* @param args.append - Append to existing values instead of replacing
* @returns Promise resolving when configuration is set
*/
function setConfig(args: {
fs: FsClient;
dir?: string;
gitdir?: string;
path: string;
value: any;
append?: boolean;
}): Promise<void>;Usage Examples:
import git from "isomorphic-git";
import fs from "fs";
// Set user name and email
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "user.name",
value: "John Doe"
});
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "user.email",
value: "john@example.com"
});
// Set core configuration
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "core.autocrlf",
value: "input"
});
// Set boolean value
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "core.bare",
value: false
});
// Set numeric value
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "http.postBuffer",
value: 524288000
});
// Append to multi-value configuration
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.url",
value: "https://backup.example.com/repo.git",
append: true
});Set up user identity for commits:
import git from "isomorphic-git";
import fs from "fs";
// Configure user identity
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "user.name",
value: "Your Name"
});
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "user.email",
value: "your.email@example.com"
});
// Verify configuration
const name = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "user.name"
});
const email = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "user.email"
});
console.log(`Configured as: ${name} <${email}>`);Configure remote repositories:
import git from "isomorphic-git";
import fs from "fs";
// Set remote URL
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.url",
value: "https://github.com/user/repo.git"
});
// Set fetch refspec
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.fetch",
value: "+refs/heads/*:refs/remotes/origin/*"
});
// Get remote configuration
const remoteUrl = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.url"
});
const fetchSpec = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "remote.origin.fetch"
});
console.log(`Remote: ${remoteUrl}`);
console.log(`Fetch: ${fetchSpec}`);Configure branch tracking:
import git from "isomorphic-git";
import fs from "fs";
// Set up branch tracking
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "branch.main.remote",
value: "origin"
});
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "branch.main.merge",
value: "refs/heads/main"
});
// Check branch configuration
const branchRemote = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "branch.main.remote"
});
const branchMerge = await git.getConfig({
fs,
dir: "/path/to/repo",
path: "branch.main.merge"
});
console.log(`Branch tracks: ${branchRemote}/${branchMerge}`);Configure core Git behavior:
import git from "isomorphic-git";
import fs from "fs";
// Configure line ending handling
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "core.autocrlf",
value: "input" // or "true" on Windows, "false" for no conversion
});
// Configure file mode tracking
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "core.filemode",
value: true // Set to false on Windows or filesystems without executable bit
});
// Configure default editor
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "core.editor",
value: "code --wait" // VS Code as editor
});
// Configure merge tool
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "merge.tool",
value: "vscode"
});Configure HTTP behavior for Git operations:
import git from "isomorphic-git";
import fs from "fs";
// Set HTTP buffer size
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "http.postBuffer",
value: 524288000 // 500MB
});
// Configure SSL verification
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "http.sslVerify",
value: true
});
// Set HTTP timeout
await git.setConfig({
fs,
dir: "/path/to/repo",
path: "http.timeout",
value: 60
});Git configuration can be stored in different locations with different precedence:
/etc/gitconfig) - Affects all users~/.gitconfig) - Affects current user.git/config) - Affects current repositoryisomorphic-git primarily works with local repository configuration. For global configuration, you would need to specify the appropriate file path.
Git configuration files use INI format:
[user]
name = John Doe
email = john@example.com
[remote "origin"]
url = https://github.com/user/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[core]
autocrlf = input
filemode = true