-
Use
degit some-repo
as a shortcut fordegit some-user/some-repo
-
Alias
cpgit
fordegit
If you're already logged into GitHub CLI (for example, as some-user
), executing degit some-repo
will implicitly act as if you entered degit some-user/some-repo
.
-
--github
or-g
option to initialize a GitHub repository in your current directory -
--public
flag to create a public GitHub repository. This must be used in conjunction with the--github
flag. -
--git
command to perform agit init
in your current working directory -
--subdir=
or-s=
parameter to define a subdirectory within a GitHub repository when operating in GitHub CLI mode
degit makes copies of git repositories. When you run degit some-user/some-repo
, it will find the latest commit on https://github.com/some-user/some-repo and download the associated tar file to ~/.degit/some-user/some-repo/commithash.tar.gz
if it doesn't already exist locally. (This is much quicker than using git clone
, because you're not downloading the entire git history.)
Requires Node 8 or above, because async
and await
are the cat's pyjamas
# use gh to clone your own github repo
npx cpgit repo-name
npm install -g cpgit
Assuming you're already logged into GitHub CLI (for example, as user
)
# same as `degit user/repo`
degit repo
# initialize a private github repo `user/somedir` from `user/repo` (commit and push immediately)
cd somedir && degit repo --github
# or like this
degit repo somedir --github
# create a public github repo `user/somedir`
degit repo somedir --github --public
# or initialize `user/somedir` from `user/templates-repo/templateA`
degit templates-repo somedir --github --subdir=templateA
# or copy organization repo you own via ssh mode to somedir
npx cpgit org/repo somedir -s=lib/dir --mode=git
# copy your repo `create-vitex`'s `template` directory to current dir, overwrite existing file
npx -y cpgit create-vitex . --force --subdir=template
The simplest use of degit is to download the master branch of a repo from GitHub to the current working directory:
degit user/repo
# these commands are equivalent
degit github:user/repo
degit [email protected]:user/repo
degit https://github.com/user/repo
Or you can download from GitLab and BitBucket:
# download from GitLab
degit gitlab:user/repo
degit [email protected]:user/repo
degit https://gitlab.com/user/repo
# download from BitBucket
degit bitbucket:user/repo
degit [email protected]:user/repo
degit https://bitbucket.org/user/repo
# download from Sourcehut
degit git.sr.ht/user/repo
degit [email protected]:user/repo
degit https://git.sr.ht/user/repo
The default branch is master
.
degit user/repo#dev # branch
degit user/repo#v1.2.3 # release tag
degit user/repo#1234abcd # commit hash
If the second argument is omitted, the repo will be cloned to the current directory.
degit user/repo my-new-project
To clone a specific subdirectory instead of the entire repo, just add it to the argument:
degit user/repo/subdirectory
If you have an https_proxy
environment variable, Degit will use it.
Private repos can be cloned by specifying --mode=git
(the default is tar
). In this mode, Degit will use git
under the hood. It's much slower than fetching a tarball, which is why it's not the default.
Note: this clones over SSH, not HTTPS.
degit --help
A few salient differences:
- If you
git clone
, you get a.git
folder that pertains to the project template, rather than your project. You can easily forget to re-init the repository, and end up confusing yourself - Caching and offline support (if you already have a
.tar.gz
file for a specific commit, you don't need to fetch it again). - Less to type (
degit user/repo
instead ofgit clone --depth 1 [email protected]:user/repo
) - Composability via actions
- Future capabilities — interactive mode, friendly onboarding and postinstall scripts
You can also use degit inside a Node script:
const degit = require('degit');
const emitter = degit('user/repo', {
cache: true,
force: true,
verbose: true,
});
emitter.on('info', info => {
console.log(info.message);
});
emitter.clone('path/to/dest').then(() => {
console.log('done');
});
You can manipulate repositories after they have been cloned with actions, specified in a degit.json
file that lives at the top level of the working directory. Currently, there are two actions — clone
and remove
. Additional actions may be added in future.
// degit.json
[
{
"action": "clone",
"src": "user/another-repo"
}
]
This will clone user/another-repo
, preserving the contents of the existing working directory. This allows you to, say, add a new README.md or starter file to a repo that you do not control. The cloned repo can contain its own degit.json
actions.
// degit.json
[
{
"action": "remove",
"files": ["LICENSE"]
}
]
Remove a file at the specified path.
- zel by Vu Tran
- gittar by Luke Edwards
MIT.