1 | # degit — straightforward project scaffolding
|
2 |
|
3 | **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.)
|
4 |
|
5 | *Requires Node 8 or above, because `async` and `await` are the cat's pyjamas*
|
6 |
|
7 |
|
8 | ## Installation
|
9 |
|
10 | ```bash
|
11 | npm install -g degit
|
12 | ```
|
13 |
|
14 | ## Usage
|
15 |
|
16 | ### Basics
|
17 |
|
18 | The simplest use of degit is to download the master branch of a repo from GitHub to the current working directory:
|
19 |
|
20 | ```bash
|
21 | degit user/repo
|
22 |
|
23 | # these commands are equivalent
|
24 | degit github:user/repo
|
25 | degit git@github.com:user/repo
|
26 | degit https://github.com/user/repo
|
27 | ```
|
28 |
|
29 | Or you can download from GitLab and BitBucket:
|
30 |
|
31 | ```bash
|
32 | # download from GitLab
|
33 | degit gitlab:user/repo
|
34 | degit git@gitlab.com:user/repo
|
35 | degit https://gitlab.com/user/repo
|
36 |
|
37 | # download from BitBucket
|
38 | degit bitbucket:user/repo
|
39 | degit git@bitbucket.org:user/repo
|
40 | degit https://bitbucket.org/user/repo
|
41 | ```
|
42 |
|
43 |
|
44 | ### Specify a tag, branch or commit
|
45 |
|
46 | The default branch is `master`.
|
47 |
|
48 | ```bash
|
49 | degit user/repo#dev # branch
|
50 | degit user/repo#v1.2.3 # release tag
|
51 | degit user/repo#1234abcd # commit hash
|
52 | ```
|
53 |
|
54 |
|
55 | ### Create a new folder for the project
|
56 |
|
57 | If the second argument is omitted, the repo will be cloned to the current directory.
|
58 |
|
59 | ```bash
|
60 | degit user/repo my-new-project
|
61 | ```
|
62 |
|
63 |
|
64 | ### See all options
|
65 |
|
66 | ```bash
|
67 | degit --help
|
68 | ```
|
69 |
|
70 |
|
71 | ## Not supported
|
72 |
|
73 | * Private repositories
|
74 |
|
75 | Pull requests are very welcome!
|
76 |
|
77 |
|
78 | ## Wait, isn't this just `git clone --depth 1`?
|
79 |
|
80 | A few salient differences:
|
81 |
|
82 | * 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
|
83 | * Caching and offline support (if you already have a `.tar.gz` file for a specific commit, you don't need to fetch it again).
|
84 | * Less to type (`degit user/repo` instead of `git clone --depth 1 git@github.com:user/repo`)
|
85 | * Composability via [actions](#actions)
|
86 | * Future capabilities — [interactive mode](https://github.com/Rich-Harris/degit/issues/4), [friendly onboarding and postinstall scripts](https://github.com/Rich-Harris/degit/issues/6)
|
87 |
|
88 |
|
89 | ## JavaScript API
|
90 |
|
91 | You can also use degit inside a Node script:
|
92 |
|
93 | ```js
|
94 | const degit = require('degit');
|
95 |
|
96 | const emitter = degit('user/repo', {
|
97 | cache: true,
|
98 | force: true,
|
99 | verbose: true
|
100 | });
|
101 |
|
102 | emitter.on('info', info => {
|
103 | console.log(info.message);
|
104 | });
|
105 |
|
106 | emitter.clone('path/to/dest').then(() => {
|
107 | console.log('done');
|
108 | });
|
109 | ```
|
110 |
|
111 |
|
112 | ## Actions
|
113 |
|
114 | You can manipulate repositories after they have been cloned with *actions*, specified in a `degit.json` file. Currently, there are two actions — `clone` and `remove`.
|
115 |
|
116 | ### clone
|
117 |
|
118 | ```js
|
119 | // degit.json
|
120 | [
|
121 | {
|
122 | "action": "clone",
|
123 | "src": "user/another-repo"
|
124 | }
|
125 | ]
|
126 | ```
|
127 |
|
128 | This will clone the contents of `user/another-repo` on top of the existing repo. The cloned repo can contain its own `degit.json` actions.
|
129 |
|
130 | ### remove
|
131 |
|
132 | ```js
|
133 | // degit.json
|
134 | [
|
135 | {
|
136 | "action": "remove",
|
137 | "files": [
|
138 | "LICENSE"
|
139 | ]
|
140 | }
|
141 | ]
|
142 | ```
|
143 |
|
144 | Additional actions may be added in future.
|
145 |
|
146 |
|
147 | ## See also
|
148 |
|
149 | * [zel](https://github.com/vutran/zel) by [Vu Tran](https://twitter.com/tranvu)
|
150 | * [gittar](https://github.com/lukeed/gittar) by [Luke Edwards](https://twitter.com/lukeed05)
|
151 |
|
152 |
|
153 | ## License
|
154 |
|
155 | [MIT](LICENSE).
|