How to create a Github repository from the command line?

Amrin - Sep 27 '21 - - Dev Community

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 pull --set-upstream origin main
Enter fullscreen mode Exit fullscreen mode

STEP 5

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

git add . && git commit -m "initial commit" && git push
Enter fullscreen mode Exit fullscreen mode

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .