Skip to content

remove

Remove a file from the git index (staging area).

await git.remove(filepath: string): Promise<void>
ParameterTypeDescription
filepathstringPath to the file to remove from index
await git.remove('README.md');
import { remove } from '@keydown-app/ts-git';
await remove({
fs,
dir,
filepath
}): Promise<void>
ParameterTypeDefaultDescription
fsFSAdapterrequiredFilesystem adapter
dirstringrequiredWorking directory path
gitdirstringjoin(dir, '.git')Git directory path
filepathstringrequiredFile path to remove from index
import { GitClient, MemoryFSAdapter } from '@keydown-app/ts-git';
const fs = new MemoryFSAdapter();
const git = new GitClient({ fs, dir: '/my-repo' });
await git.init();
// Create and stage a file
await fs.writeFile('/my-repo/temp.txt', 'temporary', 'utf8');
await git.add('temp.txt');
// Remove it from the index (but keep the file)
await git.remove('temp.txt');
// The file is now untracked
const status = await git.status('temp.txt');
console.log(status); // 'untracked'
  • add - Stage files
  • reset - Unstage files