initRepository
Creates a new repository in the specified folder.
Signature
function initRepository(
path: string,
options?: RepositoryInitOptions | null | undefined,
signal?: AbortSignal | null | undefined,
): Promise<Repository>;Parameters
- pathrequired · string
Directory path to create new repository.
- optionsnull | RepositoryInitOptions
Options which can be used to configure how a repository is initialized.
- bareboolean
Create a bare repository with no working directory. Defaults to
false. - descriptionstring
If set, this will be used to initialize the "description" file in the repository instead of using the template content.
- externalTemplateboolean
Enable or disable using external templates. If enabled, then the
template_pathoption will be queried first, theninit.templatedirfrom the global config, and finally/usr/share/git-core-templateswill be used (if it exists). Defaults totrue. - initialHeadstring
The name of the head to point HEAD at. If not configured, this will be taken from your git configuration. If this begins with
refs/it will be used verbatim; otherwiserefs/heads/will be prefixed. - mkdirboolean
Make the repo path (and workdir path) as needed. The ".git" directory will always be created regardless of this flag. Defaults to
true. - mkpathboolean
Make the repo path (and workdir path) as needed. The ".git" directory will always be created regardless of this flag. Defaults to
true. - modenumber
Set to one of the
RepositoryInitconstants, or a custom value. - noDotgitDirboolean
Normally a '/.git/' will be appended to the repo path for non-bare repos (if it is not already there), but passing this flag prevents that behavior. Defaults to
false. - noReinitboolean
Return an error if the repository path appears to already be a git repository. Defaults to
false. - originUrlstring
If set, then after the rest of the repository initialization is completed an
originremote will be added pointing to this URL. - templatePathstring
When the
externalTemplateoption is set, this is the first location to check for the template directory. If this is not configured, then the default locations will be searched instead. - workdirPathstring
The path to the working directory. If this is a relative path it will be evaluated relative to the repo path. If this is not the "natural" working directory, a .git gitlink file will be created here linking to the repo path.
- bareboolean
- signalnull | AbortSignal
Abort signal.
Returns
- Promise<Repository>
A new repository.
Examples
Basic example.
import { initRepository } from 'es-git';
const repo = await iniRepository('/path/to/repo');Create bare repository.
import { initRepository } from 'es-git';
const repo = await iniRepository('/path/to/repo.git', {
bare: true,
});