Skip to main content

On This Page

Streamlining GitHub Repository Creation with GitHub CLI

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

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

The GitHub CLI (gh) provides a command-line interface for interacting with GitHub. It allows developers to create remote repositories without leaving their local terminal environment.

Why This Matters

The traditional workflow requires switching between the terminal and a web browser to manually create a repository and copy remote URLs, introducing friction into the development cycle. Automating this via CLI ensures a consistent, repeatable process that reduces manual configuration errors when initializing new projects.

Key Insights

  • GitHub CLI (gh) enables repository creation directly from local source directories using the --source=. flag.
  • Authentication is handled via gh auth login, supporting SSH and web-browser based login flows.
  • Remote origin mapping can be automated during creation using the --remote=origin parameter.

Working Examples

Full sequence to initialize a local project, create a public GitHub repository, and push the first commit.

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

Command to specifically create a private repository instead of a public one.

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

Practical Applications

  • । Use case: Local project initialization where gh repo create automates the linking of local code to a new remote origin.

Pitfall: Forgetting to run git init before attempting to push code, resulting in failed git commands.

References:

Continue reading

Next article

Moving the Source of Truth: From Databases to Organizational Conversations

Related Content