Create a new GitHub Repository from the command line

In this blog post, I'll teach you how to make a new GitHub project using only your computer's command line. I'll explain step-by-step how to use a special command called "gh repo create".

planetaria_design_system

It's really annoying when you're working on a project on your own computer and want to save your progress on GitHub, but you haven't set up the project there yet.

That's where the GitHub CLI comes in handy. You can use it right from your terminal to create the project on GitHub and save your work there, all without switching to a web browser or another app. If you don't have the GitHub CLI yet, I've got a blog post that can help you install it.


Convert a directory to a Git repository

To turn a directory into a Git repository, imagine you've been busy working on a project on your computer for a while, and now you're ready to upload it to GitHub. The initial step is transforming the directory into a Git repository. Here's the command you'll need:

git init

Stage the files

After that, you'll need to prepare the files for committing them to your GitHub repository by staging them:

git add .

Commit the files

The next step is to commit the files:

git commit -m "initial commit"

Authorise GitHub CLI

If you're new to the GitHub CLI tool, you'll need to authorize it with your GitHub account. Running the command below will guide you through the process of granting permission for your terminal to access and make changes to your GitHub account:

gh auth login

Create your GitHub repository

Your directory is all set for Git, and your terminal is authorized to make changes to your GitHub account. Now, it's time to create the GitHub repository and upload your files into it. The command you'll need is "gh repo create". This command offers various options for different purposes.

The following command will establish a repository on GitHub named "My-NewRepo". It will be set as public. The directory you're currently in will serve as the source for this GitHub repository, and it will push the files from that directory into it.

gh repo create my-newrepo --public --source=. --remote=upstream --push

Your directory has been initialized with Git, you've got a GitHub repository ready to store your project, and all your files are securely stored there. 😊


Embrace the satisfaction of effortlessly crafting GitHub repositories with the GitHub CLI tool!

...

bilgekaanyilmaz.com