Clone Git repo to new one with no connections to the original
The new repo will have an empty history and no remotes, everything else will be as in the original. Note that only the default branch (if more than one exists) will be cloned.
hh lohmann <hh.lohmann@gmail.com>
import { gitCloneToNewRepo } from 'git-clone-to-new-repo'
gitCloneToNewRepo( urlOfRepoToClone, nameForNewRepo )
gitCloneToNewRepo( urlOfRepoToClone, nameForNewRepo, branchName )
URL of the repo to clone
Name / path for repo to create
Optional: Name for branch with which new repo is created
true on success, false else gitCloneToNewRepo(
'https://github.com/acme-com/solve-all-problems',
'my-super-solver'
)
gitCloneToNewRepo(
'https://github.com/acme-com/postpone-hard-problems',
'/home/joedoe/backlog/hard-problems'
)
gitCloneToNewRepo(
'https://github.com/acme-com/soft-problems',
'my-guaranteed-solver',
'dev-branch'
)
Pick for your preferred package manager:
npm i git-clone-to-new-repo
pnpm i git-clone-to-new-repo
bun i git-clone-to-new-repo
# 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-clone-to-new-repo
The new repo will be initialized, but without any commit. This allows you to further refine the new repo by deleting or changing files copied from the original repo in advance.
Unlike degit not meant for automation, therefore far simpler and sometimes faster
Cloning is done with “–depth 1” to clone only the current state. Note that this may only have for large repos an effect on the size of what is downloaded since in very small repos the Git tracking may consume more space than the tracked files. Note also that the actual size of the new repo will be that after deleting the former Git tracking.