Create a Github Repo From the Command Line

Ole Ersoy
2 min readMar 22, 2024


Image by Virvoreanu Laurentiu from Pixabay


We want to create GitHub repo via the terminal.


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

At this point you have a repository that looks just like the minimal vanilla one you would create on 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" >>
git init
git add
git commit -m "first commit"
git branch -M main
git remote add origin
git push -u origin main

So for example to add the do this.

echo "# ghrepo" >>
git add && git commit -m "chore: add"
git remote add origin
git push -u origin main

If you refresh the repo URL in your browser you’ll see that it has the 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.