How to create a Github repository from the command line?

How to create a Github repository from the command line?

·

2 min read

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 : docs.github.com/en/github/importing-your-pr..

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.