You can clone repositories without the whole history
- Published at
- Updated at
- Reading time
I was browsing electron boilerplates today, and inside of the electron-react-boilerplate I found something interesting. The getting started guide include a
git clone --depth=1.
git clone --depth=1 https://github.com/chentsulin/electron-react-boilerplate.git your-project-name
What's that? I tried it immediately.
/tmp 😩 🐿 😪 ▶ git clone --depth=1 https://github.com/chentsulin/electron-react-boilerplate.git your-project-name Cloning into 'your-project-name'... ... /tmp 😋 😦 🐍 ▶ cd your-project-name /tmp/your-project-name 😏 😝 😷 master ヾ(⌐■_■)ノ ▶ git lg * 586b84f Amila Welihinda - (grafted, HEAD -> master, origin/master, origin/HEAD) Misc code style changes to menu.js (5 weeks ago) (END)
git's documentation defines the
depth argument as follows:
Create a shallow clone with a history truncated to the specified number of commits.
depth to define that you don't want to clone and include thousands of unrelated commits from the past when cloning a boilerplate project. Limiting and truncating the history is valuable for projects such as
Ideally, there would be a way to use git to clone projects without the
.git directory. Unfortunately, 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 git directory. The command
npm init using is easy to remember and downloads history-free projects. Read more about it in my discovery post.
- How to apply directory dependent git configuration using conditional imports
- How to add a directory but ignore included files in git
- A git alias to show a detailed git branch overview
- How to use git's file diff outside of git repositories
- git commit accepts several message flags (-m) to allow multiline commits