Skip to main content

Command Palette

Search for a command to run...

How to create a Github repository from the command line?

Updated
2 min read
How to create a Github repository from the command line?
A

I am a Front end developer and content creator.

If you are like me, you don't like to create a GitHub repository on the GitHub website.

That's where the Github CLI comes. Using GitHub CLI we can create a GitHub repository with just a few commands from the command line.

Before creating a repository using CLI we need to install it. You can install Github CLI from this Link.

STEP 1

Using the command line, navigate to the folder you trying to make a repository. Then using the below command initialize the local directory as a Git repository.

git init -b main

STEP 2

To create a repository on Github we are going to use this command. Make sure to change the "project-name" with the name you want your repository to be.

gh repo create project-name

STEP 3

Now, Follow the interactive prompts. If you don't like it. you can specify arguments to skip these prompts. For more information about possible arguments, see the GitHub CLI manual.

STEP 4

Pull changes from the new repository that you created.

git push --set-upstream origin main

STEP 5

Lastly, add files edit files and push them to Github.

git add . && git commit -m "initial commit" && git push

Resources : https://docs.github.com/en/github/importing-your-projects-to-github/importing-source-code-to-github/adding-an-existing-project-to-github-using-the-command-line

Conclusion

I like this approach of making a Github repo. Cause I get to click less. If you have any questions please leave a comment. I will be more than happy to talk to you.

And if you like my articles. Follow me on Twitter at @coderamrin

Thanks for reading.

Have a nice day.

V

Nice article :) i surely start using this.

1
A
amrin4y ago

Thank you so much, I really appreciate it. and it is really cool, I just hate to create a repo by clicking.

V

Too bad that theres no delete functionality but i think that would be too dangerous for a bigger project. amrin

1
A
amrin4y ago

what delete functionality do you mean? Ville Pakarinen

V

I mean how to delete repo. amrin

1
A
amrin4y ago

Yeah looks like I couldn't find it yet Ville Pakarinen
but you can check this doc: https://cli.github.com/manual/gh_alias_delete

1