How to initialize a github repo using the Github API
Whenever I’m creating a new project from console I always need to leave it and go to github webpage to create a new repository and come back to console to push the changes.
There some ways to create the repository via CLI.
1. Via cURL
By using the github API and cURL it is really easy to create a new repository:
From the response is possible to get the git url to add a remote and push the changes:
By default a public repository is created, if you wish to create a private one you need to use:
2. Adding a alias to git
It is cumbersome to type the same commands every time, so a git alias make this task pretty straightforward:
You can generate a personal access token and add it to the command above, otherwise cURL will prompt you to enter your password.
From now on you only need to use the alias created above:
It is also possible to enhance the command by making it responsible for add a new remote automatically:
Using this option you just need to create the repository and push the changes:
PS: For a silent output you can use: cURL -s -o /dev/null
3. Using a Ruby Gem
There are some gems out there that not only make it easy to create repository but to perform all the operations provided by Github API.