fetch
Download new data and update tips.
Convenience function to connect to a remote, download the data, disconnect and update the remote-tracking branches.
Signature
class Remote {
fetch(
refspecs: string[],
options?: FetchRemoteOptions,
signal?: AbortSignal,
): Promise<void>;
}
Parameters
- refspecsrequired · string[]
Refspecs to fetch from remote.
- optionsnull | FetchRemoteOptions
Options for fetch remote.
- fetchFetchOptions
Options which can be specified to various fetch operations.
- credentialCredential
A interface to represent git credentials in libgit2.
- customHeadersstring[]
Set extra headers for this fetch operation.
- depthnumber
Set fetch depth, a value less or equal to 0 is interpreted as pull everything (effectively the same as not declaring a limit depth).
- downloadTagsAutotagOption
Set how to behave regarding tags on the remote, such as auto-downloading tags for objects we're downloading or downloading all of them. The default is to auto-follow tags.
-
Unspecified
: Use the setting from the remote's configuration
-Auto
: Ask the server for tags pointing to objects we're already downloading
-None
: Don't ask for any tags beyond the refspecs
-All
: Ask for all the tags - followRedirectsRemoteRedirect
Set remote redirection settings; whether redirects to another host are permitted. By default, git will follow a redirect on the initial request (
/info/refs
), but not subsequent requests.-
None
: Do not follow any off-site redirects at any stage of the fetch or push.
-Initial
: Allow off-site redirects only upon the initial request. This is the default.
-All
: Allow redirects at any stage in the fetch or push. - proxyProxyOptions
Set the proxy options to use for the fetch operation.
- autoboolean
Try to auto-detect the proxy from the git configuration. Note that this will override
url
specified before. - urlstring
Specify the exact URL of the proxy to use. Note that this will override
auto
specified before.
- autoboolean
- pruneFetchPrune
Set whether to perform a prune after the fetch.
-
Unspecified
: Use the setting from the configuration.
-On
: Force pruning on.
-Off
: Force pruning off
- credentialCredential
- reflogMsgstring
- fetchFetchOptions
- signalnull | AbortSignal
Abort signal.
Examples
import { openRepository } from 'es-git';
const repo = await openRepository('/path/to/repo');
const remote = repo.getRemote('origin');
// Fetching data from the "main" branch
await remote.fetch(['main']);
// Providing an empty array fetches data using the default Refspec configured for the remote
await remote.fetch([]);