Member-only story
Create GitHub Repos Remotely
With a single command, using a Bash script

I’m always looking for ways to simplify my coding environment. Until recently, I was hosting my own Git server for use with private repos and projects for clients that can’t be committed to GitHub. Once GitHub started offering unlimited private repos for free, this was no longer necessary.
However, one thing I was missing was the ability to automatically create repos with a Bash script, something I configured with my private Git server, which was hosted using Gitea. Gitea provides an API for this and as it turns out, so does GitHub!
If you’d like to look at the GitHub API documentation, it can be found here.
I’m going to cover how to create a simple Bash script using GitHub’s repository API and show you how you can do this in your programming environment.
Before We Start
This tutorial assumes you’re using a Mac, however, these same steps will work fine on any Linux machine. It also assumes you’ve already installed Git or Xcode Command Line Tools, which include Git.
Generate a Personal Access Token
In order to access GitHub’s API, we will need a Personal Access Token. This token is used as authorization to GitHub’s API to make requests for your account only so it’s very important to keep it safe — don’t commit the token to GitHub and don’t share it with anyone.
Start by logging into your GitHub account, select the user menu in the upper right-hand corner and choose Settings. From the Settings menu, select Developer Settings on the bottom-left. From there, click the Generate new token
button on the top-right. Take a look at the GIF below if you get lost.

In the note field, give your token a name or phrase that easily identifies its purpose. I used “Repo management”.
Note that the API we are using can also be used to modify your GitHub account in significant ways, so you’ll probably want to restrict the token from doing just that. My settings are configured…