hrbrmstr's Daily Drop

Share this post

Drop #252 (2023-05-02): Stop Cloning Around

dailyfinds.hrbrmstr.dev

Discover more from hrbrmstr's Daily Drop

A digest of all the interesting data, packages, blogs and papers covering lots of programming languages, CLI utilities, cybersecurity, data visualization, data science, web-scraping and more!
Continue reading
Sign in

Drop #252 (2023-05-02): Stop Cloning Around

degit / tigued; bash it all; Project Templating Resource Roundup

boB Rudis
May 2, 2023
3
Share this post

Drop #252 (2023-05-02): Stop Cloning Around

dailyfinds.hrbrmstr.dev
2
Share

How many times have you git cloned a repository just to use it as a template for another project? In doing so, all that came before it also comes along for the ride, slowing down the entire process, and leaving you with some messes to clean up before getting to work. Even if you're a clever one and use --depth 1 you still have some cleaning up to do, plus the inefficiency of a long command line and re-wasted bandwidth for each new clone.

There's got to be a better way to deal with language-agnostic project scaffolding…and, there is!

Today, we'll look a three-different1 ways to (mostly) accomplish the same thing: scaffold a local project (quickly) from a remote git repository.

degit / tigued

a book and a small figurine on a desk
Photo by Praveen Thirumurugan on Unsplash

Project scaffolding, in any coding context, refers to the process of setting up the initial structure, files, and configurations for a new project based on predefined templates or boilerplates. This process helps coders quickly start new projects by providing a basic structure that can be customized and built upon.

Scaffolding tools automate project creation by generating an entire directory structure based on the chosen template and user inputs. These tools save time and effort by providing a consistent starting point for projects, allowing coders to focus on implementing specific features and functionality rather than setting up the project's basic structure.

Degit, and the community fork of it — tigued — are straightforward project scaffolding tools used for creating copies of git repos without cloning or downloading the entire repository history. Both tools are designed to be both elementary and straightforward to use. They're also pretty lightweight, since they are language-agnostic and focus on providing basic templating capabilities without the complexity of additional language- or project-specific features. This makes either an excellent choice for folks who play across many ecosystems and want to use the same idiom to kick-start new endeavors.

No longer being a slave to the mundanity and chained to the inconvenience of re-initializing git trees and resetting origin remote pointers when starting new template-driven projects, you can unleash2 your full potential and focus on getting stuff done vs. how to get started.

Unlike most of the other tools we're covering today, degit/tigued support all major coding hubs, including GitHub, GitLab, BitBucket, and Sourcehut, making them versatile tools for coders and teams working with/across different repositories.

One especially 🤩 feature — if you're stuck in crappy internet land like I am — is caching. Once you de-git a template, it’s cached locally for future use (and groks cache invalidation). This saves bandwidth, and can save your hide if you forget to deliberately make a master copy of a remote template and need to start a new project when your internet is down (again, boB).

You can also get a bit fancy with post “clone” actions, but I prefer to keep it simple and just rely on the basic functionality.

The repos are quite friendly with many examples, so no need for me to put extra wear and tear on the cmd-c/cmd-v keys.

Share

bash it all

green and black digital device
Photo by Gabriel Heinzer on Unsplash

If you only care about GitHub and your templating needs are, at best, meager, then look no further than this short bash “clone” of degit. With proper credit given in that link, here's the entirety of the script:

#!/usr/bin/env bash
# Note: This only supports GitHub, no caching nor fancy error handling

set -euo pipefail

repo="${1}"
directory="${repo/*\//}"

mkdir -p "${directory}"

curl \
  --location "https://api.github.com/repos/${repo}/tarball" | \
  tar --extract \
    --ungzip \
    --strip-components=1 \
    --directory "${directory}"

Tis nowhere near as elegant nor handy (e.g., it has no fancy bits like caching), but it does get the job done in a pinch.

Share

Project Templating Resource Roundup

herd of sheep on green grass field during daytime
Photo by Andrea Lightfoot on Unsplash

While degit is cool and its distant bash cousin is handy, there are some giants in this space you likely have heard of, but may never have tried. So, here is a tasting menu for you to sample at your leisure. Just make sure to let us know which one(s) you like best if you do decide to play the template field a bit.

  • Cookiecutter is a cross-platform, command-line utility that creates projects from templates. It's written in Python, but can be used to create projects in any language or framework. It is _hughely popular, which means you can also find many community-contributed templates to use or riff from.

  • Yeoman is yet-another project scaffolding tool that provides a “generator ecosystem”. It, too, is language- and framework-agnostic and allows you to create custom generators for various project types. Many Yeoman generators can also be found on the npm registry: https://www.npmjs.com/search?q=keywords:yeoman-generator.

  • Lazybones is a simple and flexible project creation tool that is compatible with any programming language or framework. It's written in Groovy and can fetch project templates from git repositories or other sources. You can find Lazybones templates strewn across the internets, but can focus your search a bit in GitHub to see if there are ones you can just start using.

  • On GitHub, you can create “template repositories” which can be used as a solid base for creating new repositories, even though they lock you in to Microsoft's terrible platform. With just one click/tap of the “Use this template” button in an existing template repository, you are seconds away from having a fresh new project directory3.

  • Similarly, GitLab Project Templates lock you in to GitLab's lesser-evil platform, and also supports creating new projects based on existing project templates. Anyone can contribute to an ever-growing list of GitLab templates.

    Share

FIN

If I missed your fav template generator, drop a note in the comments or wherever strong opinions (loosely held) can be found. ☮

1

It’s really way more than three, given the list in the last section.

2

This is what happens when I let LanguageTool’s new AI thingy rewrite one of my sentences. o_O

3

I feel like this feature should have caught on more, but perhaps there is yet hope for humankind.

3
Share this post

Drop #252 (2023-05-02): Stop Cloning Around

dailyfinds.hrbrmstr.dev
2
Share
Previous
Next
2 Comments
Share this discussion

Drop #252 (2023-05-02): Stop Cloning Around

dailyfinds.hrbrmstr.dev
Richard Careaga
May 2Liked by boB Rudis

Hey, Bob. For some reason the dropfeed hasn’t been showing up in my Substack inbox since Tax Day. If you’re seeing a falloff in engagement (if it’s not due to something peculiar to my account) that might be something to trace.

Expand full comment
Reply
Share
1 reply by boB Rudis
1 more comment...
Top
New
Community

No posts

Ready for more?

© 2023 boB Rudis
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing