Creating a GitHub repository from the command line.

If you’re like me, you hate swapping out of terminal to log into GitHub when creating a new repository.  It an always jarring step that gets you out of coding flow. You can accomplish the very same thing at the command line, and never open a web browser. All you need is the cURL library (found in almost every popular flavor of Linux and OSX today), and your personal GitHub API token.

This technique calls on GitHub’s API to work its magic. You will therefore need to login to GitHub, browse to the “Your Account – Account Admin” section and find your unique API token listed there. Copy the token down for reference purposes.

When you are ready to create a new GitHub repository for your code (ie: just before “git remote add origin” step), issue the following command using the cURL URL transfer tool:

$ curl -F 'login=<your_login_name>' -F 'token=<your_API_token>' https://github.com/api/v2/json/repos/create -F 'name=<your_repo_name>' -F 'description=<your_repo_summary>'

GitHub will reply to your API call with a flurry of JSON, while it creates your new repo in the background:

Your repo will now be ready to push code into. Login into GitHub to validate that it is indeed there. That’s it!

UPDATE 1/10/2013: Github terminated its API on June 1, 2012, which negates the ability to create the repo. More detail can be found here.

 

  • Svetoslav

    Hi Jeff,
    Probably the guys from GitHub changed something since Oct 2011, because I couldn’t find the API Token as described in your post.

    Could you update the info a little bit?

    I have noticed that there is “Register Application” button in the Account menu, which allows you to register an app with OAuth and thus create API Token for your app…

    Should I do this in order to obtain a Token and what app to register? I simply want to be able to create new remote repo-s without having to go to Github site every time.

    Thank you for your post.

  • Nick

    Brilliant. Thanks m8