I created a new local Git repository:
~$ mkdir projectname
~$ cd projectname
~$ git init
~$ touch file1
~$ git add file1
~$ git commit -m 'first commit'
Is there any git command to create a new remote repo and push my commit to GitHub from here? I know it's no big deal to just fire up a browser and head over to Create a New Repository, but if there is a way to achieve this from the CLI I would be happy.
I read a vast amount of articles but none that I found mention how to create a remote repo from the CLI using git commands. Tim Lucas's nice article Setting up a new remote git repository is the closest I found, but GitHub does not provide shell access.
For rep reasons, I can't add this as a comment (where it would better go with bennedich's answer), but for Windows command line, here is the correct syntax:
curl -u YOUR_USERNAME https://api.github.com/user/repos -d "{\"name\":\"YOUR_REPO_NAME\"}"
It's the same basic form, but you have to use double quotes (") instead of single, and escape the double quotes sent in the POST parameters (after the -d flag) with backslashes. I also removed the single quotes around my username, but if your username had a space (possible?) it would probably need double quotes.
I recently found out about create-github-repo. From the readme:
Install:
Usage:
Or:
If you install defunkt's excellent Hub tool, then this becomes as easy as
git create
In the words of the author, "hub is a command-line wrapper for git that makes you better at GitHub."
here is my initial git commands (possibly, this action takes place in
C:/Documents and Settings/your_username/
):I've created a Git alias to do this, based on Bennedich's answer. Add the following to your
~/.gitconfig
:To use it, run
from anywhere inside the local repository, and enter your Github password when prompted.
What you need is hub. Hub is a command-line wrapper for git. It has been made to integrate with native git using alias. It tries to provide github actions into git including creating new repository.