npm-package
Copy file / folder from Git repo without cloning
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>
This page may be displayed more optimal in its GitHub Pages view
Caution
- Does not check if a file / folder with the same name already exists in your target - this is up to you, especially in case you explicitly want to overwrite / reset existing files (cf. Details)
Synopsis
import { gitCopyFileFolder } from 'git-copy-file-folder'
gitCopyFileFolder( sourceRepo, fileOrFolder)
gitCopyFileFolder( sourceRepo, fileOrFolder, targetPath )
Parameters
sourceRepo
URL of the repo from which fileOrFolder should be copied
fileOrFolder
Name / path for the file / folder to be copied from the sourceRepo
- Interpreted relative to the source repo's root, i.e.
src/index.jsof repoxwould bex/src/index.js
targetPath
Optional: Existing path to which fileOrFolder should be copied to
- Default: current folder
Returns
trueon success,falseelse
Examples
gitCopyFileFolder(
'https://github.com/acmecorp/solve-all-problems',
'secretsolutions'
)
gitCopyFileFolder(
'https://github.com/acmecorp/solve-all-problems',
'secretsolutions/solution-42.js',
'ripped-stuff/acme/'
)
Installation
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
Details
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)
Tests
- Code tests to be run with Node.js / Bun available in Source Code
Source Code
License
- See LICENSE file included here and in Source Code
