CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-isomorphic-git

A pure JavaScript implementation of git for node and browsers

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

configuration.mddocs/

Configuration Management

Reading and writing Git configuration values.

Capabilities

Get Configuration Value

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);

Get All Configuration Values

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);

Set Configuration Value

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
});

Common Configuration Patterns

User Configuration

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}>`);

Remote Configuration

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}`);

Branch Configuration

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}`);

Core Configuration

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"
});

HTTP Configuration

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
});

Configuration Locations

Git configuration can be stored in different locations with different precedence:

  1. System config (/etc/gitconfig) - Affects all users
  2. Global config (~/.gitconfig) - Affects current user
  3. Local config (.git/config) - Affects current repository

isomorphic-git primarily works with local repository configuration. For global configuration, you would need to specify the appropriate file path.

Configuration File Format

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

docs

advanced-operations.md

branch-management.md

commit-operations.md

configuration.md

error-handling.md

index.md

object-operations.md

reference-management.md

remote-operations.md

repository-operations.md

working-directory.md

tile.json