> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Create a new GitHub Repository from the command line
- URL: https://www.techielass.com/create-a-new-github-repository-from-the-command-line/
- Published: 2022-02-22T08:01:00.000Z
- Updated: 2023-12-06T11:14:16.000Z
- Description: In this blog post I show you how to create a new GitHub repository from the command line. I explain how the gh repo create command.
- Author: Sarah Lean
- Tags: GitHub, CLI

It can be frustrating when you are working on a project on your local machine and need to commit some changes to GitHub, but you haven't set up that repository. 

The GitHub CLI can help in this situation; from your terminal, you can create that repository and commit your project. All without leaving your terminal or Integrated Development Environment (IDE). If you haven't got the GitHub CLI installed, [check out my blog post](https://www.techielass.com/install-github-cli-on-windows/) that covers the best ways to do that. 

## Convert a directory to a Git repository

So, you've been working on a project on your local machine for the last few hours, and you want to commit that project to a GitHub repository. The first step is to [convert the directory to a Git repository](https://www.techielass.com/convert-a-folder-to-a-git-repository/). The command to use is: 

```powershell
git init

```

## Stage the files

The next step would be to stage the files so they can be committed to your GitHub repository: 

```powershell
git add .

```

## Commit the files

The next step is to commit the files:

```powershell
git commit -m "initial commit"

```

## Authorise GitHub CLI

If you have never used the GitHub CLI tool before, you must authorise it with your GitHub account. If you type in the following command, it will walk you through allowing your terminal to change your GitHub account. 

```powershell
gh auth login

```

## Create your GitHub repository 

Your directory is Git ready, and your terminal is authorised to change your GitHub account. The next step is to create that GitHub repository and push your files into that repository. The command you want to use is **gh repo create**. This command has a lot of switches you can use for different reasons. 

The command below will create a repository in GitHub called *"My-NewRepo"*. It will be a public repository. The directory you are in will be the source for that GitHub repository, and the push the files in the directory to it. 

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

```

Your directory is now Git initiated, you have a GitHub repository to store your project, and the files are stored there. 😊

### Enjoy this new found joy of being able to create GitHub repositories using the GitHub CLI tool!

![If you like my work please support me by buying me a coffee](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/02/blogcoffee-1.png)

If you like my work please support me by buying me a coffee

[*Command Line*](https://icons8.com/icon/9hLY0P1ixONa/command-line?ref=techielass.com) *icon by* [*Icons8*](https://icons8.com/?ref=techielass.com)