Copy a file or folder from a Git repo instead of cloning, i.e. without a connection to the source
Changes in the original repo will not affect the copy of the file / folder and vice versa.
Helpful to reuse specific contents of another repo in a current one without mixing both repos.
hh lohmann <hh.lohmann@gmail.com>
import { gitCopyFileFolder } from 'git-copy-file-folder'
gitCopyFileFolder( sourceRepo, fileOrFolder)
gitCopyFileFolder( sourceRepo, fileOrFolder, targetPath )
URL of the repo from which fileOrFolder should be copied
Name / path for the file / folder to be copied from the sourceRepo
src/index.js of repo x would be x/src/index.jsOptional: Existing path to which fileOrFolder should be copied to
true on success, false else gitCopyFileFolder(
'https://github.com/acmecorp/solve-all-problems',
'secretsolutions'
)
gitCopyFileFolder(
'https://github.com/acmecorp/solve-all-problems',
'secretsolutions/solution-42.js',
'ripped-stuff/acme/'
)
Pick for your preferred package manager:
npm i git-copy-file-folder
pnpm i git-copy-file-folder
bun i git-copy-file-folder
# For Yarn you should double check docs for your and / or
# current Yarn version, newer versions do not treat `i package_name`
# as an alias for `add ...` and exclude global installations
yarn add git-copy-file-folder
Only one file / folder per call (multiple files / folders or globbing goes beyond the current time budget for this project)
Does not check if a file / folder with the same name already exists in your target before probably overwriting it, partly for simplicity, partly to give surrounding code full control about e.g. deciding if overwriting an old version with a newer one or a diverged / corrupted version with the original one may be explicitly intended.
Copying takes place via a temporary sparse clone and a sparse-checkout there (deleted after copying the file / folder requested)