How to Create a GitHub Repository from the Terminal Using GitHub CLI

작성자

카테고리:

← 피드로
DEV Community · Cristian Jonhson Alvarez · 2026-06-11 개발(SW)
Cover image for How to Create a GitHub Repository from the Terminal Using GitHub CLI

Cristian Jonhson Alvarez

When working on a local project, we usually create the repository on GitHub first, copy the remote URL, and then connect it to our local project.

But there is a cleaner way to do it directly from the terminal using GitHub CLI.

1. Initialize Git in Your Project

Go to your project folder:

cd your-project-name

Enter fullscreen mode Exit fullscreen mode

Initialize Git:

git init

Enter fullscreen mode Exit fullscreen mode

2. Authenticate with GitHub CLI

If you have not logged in yet, run:

gh auth login

Enter fullscreen mode Exit fullscreen mode

During the process, you can choose:

GitHub.com
SSH
Login with a web browser

Enter fullscreen mode Exit fullscreen mode

3. Create the Remote Repository from Local

To create the repository on GitHub and add it as origin, run:

gh repo create repository-name --public --source=. --remote=origin

Enter fullscreen mode Exit fullscreen mode

Example:

gh repo create IA_ML_DL_python_fundamentos --public --source=. --remote=origin

Enter fullscreen mode Exit fullscreen mode

For a private repository:

gh repo create repository-name --private --source=. --remote=origin

Enter fullscreen mode Exit fullscreen mode

4. Verify the Remote

Check that origin was added correctly:

git remote -v

Enter fullscreen mode Exit fullscreen mode

You should see something like:

origin  [email protected]:username/repository-name.git (fetch)
origin  [email protected]:username/repository-name.git (push)

Enter fullscreen mode Exit fullscreen mode

5. Create the First Commit

Add your files:

git add .

Enter fullscreen mode Exit fullscreen mode

Create the first commit:

git commit -m "Initial commit"

Enter fullscreen mode Exit fullscreen mode

6. Push the Project to GitHub

Make sure your main branch is named main:

git branch -M main

Enter fullscreen mode Exit fullscreen mode

Push your project:

git push -u origin main

Enter fullscreen mode Exit fullscreen mode

Full Command Summary

git init
gh auth login
gh repo create repository-name --public --source=. --remote=origin
git add .
git commit -m "Initial commit"
git branch -M main
git push -u origin main

Enter fullscreen mode Exit fullscreen mode

Conclusion

Using gh repo create allows you to create a GitHub repository directly from the terminal, connect it as origin, and push your local project without manually creating the repository from the browser.

It is a faster, cleaner, and more professional workflow for starting new projects on GitHub.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다