Creating Websites with the GitHub and Netlify Command Line Tools
I've got like 150 sites hosted on Netlify. Each one backed by a corresponding GitHub repo. I set them all up by hand. I never took the time to learn the CLIs because when I wanted to make a new site I didn't want to have to dig into figuring other stuff out. Plus, I can go from zero to deployed site in under 5min.
But, I'm gonna do Weird Web October. Building one site for each day of the month. I want to go ahead and prep the repos and domain names now. That way, all I have to do is code the actual site each day. The idea of making 31 sites by hand in one sitting is not appealing. It's time to bring the command line into play.
Foundation Template
I use a personal static site builderssb to make my sites. Each one starts out with a few scaffold files to get started. I'd been just copying in manually. Since I'm going CLI it's time to get into GitHub Templates to take care of that for me.
First step is to make a repo that'll turn into the template:
That creates a repo named wwo-2025-template and clones it down in a subdirectory with the same name.
After I drop my template/boilerplate/scaffold files in I commit and push the changes with the standard git commandsbranch:
Turning the repo into a template that can be used to make other repos is done with:
(The command looks a little weird to me. It reads like I'm going to be editing the template, but really it just that it's editing the repo to turn the --template flag on)
Stamping Out Sites
Making a new repo/site that uses the template is done with:
Quick and easy.
Even better, I can use the command in scripts when I want to make a bunch of sites:
#!/bin/bash
for
do
The script goes through the numbers making a new repo and cloning it down for each one. The process takes a second or two per repo, but moves at a steady clip. The output looks like this:
✓ Created repository alanwsmith/wwo-2025-0 on github.com https://github.com/alanwsmith/wwo-2025-0 Cloning into 'wwo-2025-0'... ✓ Created repository alanwsmith/wwo-2025-1 on github.com https://github.com/alanwsmith/wwo-2025-1 Cloning into 'wwo-2025-1'... ✓ Created repository alanwsmith/wwo-2025-2 on github.com https://github.com/alanwsmith/wwo-2025-2 Cloning into 'wwo-2025-2'... ✓ Created repository alanwsmith/wwo-2025-3 on github.com https://github.com/alanwsmith/wwo-2025-3 Cloning into 'wwo-2025-3'...
Shipping to Netlify
Setting up a site repo to push to Netlify is done by running this command inside the repos folder:
The command line walks through a series of questions about how you want to set up the site. From what I'm seeing in the docsinitdocs it doesn't look like there are flags to fully automate the process. A minor bummer, but not a huge deal.
The command ends by triggering a deployment of the site. The status command includes the URL of the site you can checkout once it has deployed
TODO
- Figure out how to set a subdomin DNS record via the Netlify API.
Endnotes
You have to go through an initial setup with:
gh auth login
I'm using gh repo new. It's an alias for gh repo create. Look for the create command in the docs to see all the options.
Deleting repos can be done from the command line. I did that a few times during testing. You have to run gh auth refresh -s delete_repo before running a gh repo delete command to get the permissions set up.
There's a login dance to do with the netlify CLI too. Check the docs for details.
There's also:
netlify --telemetry-disable
I'm a big fan of not sending out any more info that is necessary so I turn it off.
References
Footnotes
TODO: Link to simple site builder and post on making your own static site generator.
I'm skipping branching here since that's not what this page is really about.