You can clone repositories without the whole history
- Published at
- Updated at
- Reading time
- 2min
I browsed electron boilerplates today and I discovered something interesting in the electron-react-boilerplate.
The getting started guide includes advises to use git clone --depth=1
.
git clone --depth=1 https://github.com/chentsulin/electron-react-boilerplate.git your-project-name
What's this depth
argument? Let's find out!
$ git clone --depth=1 https://github.com/chentsulin/electron-react-boilerplate.git your-project-name
Cloning into 'your-project-name'...
$ cd your-project-name
$ git log
* 586b84f Amila Welihinda - (grafted, HEAD -> master, origin/master, origin/HEAD) Misc code style changes to menu.js (5 weeks ago)
(END)
Look at the entries shown in the git log. Thanks to the --depth=1
argument the just cloned repository only includes a single commit. You might know that cloning an active project can take some moments because you're downloading the entire history.
But thanks to --depth
getting the source code was super speedy!
git's documentation defines the depth
argument as follows:
Create a shallow clone with a history truncated to the specified number of commits.
Use depth
to define that you don't want to clone and include thousands of unrelated commits from the past when checking out a project.
Ideally, there would be a way to use git to clone projects without the
directory. But I don't think you can do that with git, though. (if you know how to do it, please let me know)
But if you have a recent version of npm
installed on your machine, I recently discovered an intuitive command to download GitHub projects without history and
directory.
The command npm init using
is easy to remember and downloads history-free projects. Read more about it in my discovery post.
# Download chentsulin/electron-react-boilerplate without
# history or .git directory
$ npm init using chentsulin/electron-react-boilerplate
npm init using
uses the degit package under the hood. You can use that one, too, if you like.
# Download chentsulin/electron-react-boilerplate without
# history or .git directory
$ degit chentsulin/electron-react-boilerplate
Happy downloading!
Join 5.5k readers and learn something new every week with Web Weekly.