Create a Github Repo From the Command Line

Ole Ersoy
2 min readMar 22, 2024

--

Image by Virvoreanu Laurentiu from Pixabay

Scenario

We want to create GitHub repo via the terminal.

Approach

Make sure you have github SSH keys setup so that you can authenticate and push without having to enter credentials.

When you run gh auth login it will ask to use your SSH keys.

Install the Github CLI.

On MacOS you can use brew.

brew install gh

First you need to run gh auth login to setup authentication.

After that is done perform the following steps on your commandline.

mkdir ghrepo && cd ghrepo && git init -b main
gh repo create ghrepo --public

You should get the following confirmation message like this one.

✓ Created repository fireflysemantics/ghrepo on GitHub
https://github.com/fireflysemantics/ghrepo

At this point you have a repository that looks just like the minimal vanilla one you would create on Github.com with the user interface.

If you visit the page you’ll see it has instructions like these for setting up the rest of the repository. The below would add a

echo "# ghrepo" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:fireflysemantics/ghrepo.git
git push -u origin main

So for example to add the README.md do this.

echo "# ghrepo" >> README.md
git add README.md && git commit -m "chore: add README.md"
git remote add origin git@github.com:fireflysemantics/ghrepo.git
git push -u origin main

If you refresh the repo URL in your browser you’ll see that it has the README.md file.

Since we are done with the repo we can now delete it.

gh repo delete ghrepo
Type fireflysemantics/ghrepo to confirm deletion: fireflysemantics/ghrepo

Note that it asks for confirmation.

If we now refresh the github page the we get a 404 page.

--

--

Ole Ersoy
Ole Ersoy

Written by Ole Ersoy

Founder of Firefly Semantics Corporation

No responses yet