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.
This can be done with three commands:
(updated for v3 Github API)
Explanation of these commands...
Create github repo
Define where to push to
Push local repo to github
I wrote a nifty script for this called Gitter using the REST APIs for GitHub and BitBucket:
https://github.com/dderiso/gitter
BitBucket:
GitHub:
-c
= create new repo-r
= repo provider (g = GitHub, b = BitBucket)-n
= name the repo-l
= (optional) set the language of the app in the repocreate a new repository on the command line
push an existing repository from the command line
You can create a GitHub repo via the command line using the GitHub API. Check out the repository API. If you scroll down about a third of the way, you'll see a section entitled "Create" that explains how to create a repo via the API (right above that is a section that explains how to fork a repo with the API, too). Obviously you can't use
git
to do this, but you can do it via the command line with a tool likecurl
.Outside of the API, there's no way to create a repo on GitHub via the command line. As you noted, GitHub doesn't allow shell access, etc., so aside from the GitHub API, the only way to create a repo is through GitHub's web interface.