Last Updated: February 25, 2016
· metaraine
Dushanbe red 500x500

Create new github repo from command line

Note: While the below is a great way to do it yourself, hauleth suggested Hub which does all this and more!

Create a new shell script called "git-create"


test -z $repo_name && echo "Repo name required." 1>&2 && exit 1

curl -u 'your_github_username' -d "{\"name\":\"$repo_name\"}"

As tchaudhri mentioned in the comments, don't forget to make the above script executable by running chmod +x git-create.

Make sure you save it somewhere on your PATH. If you don't have a directory for custom shell scripts on your PATH, you can save it in ~/bin and then add that to your PATH by editing ~/.bash_profile as follows:

export PATH

Now you can easily create a new github repo from with the following command:

git create mynewrepo

If you assume this command is run from a valid local git repo (or the folder containing what should become the repo) you can add the following lines to "git-create" to automatically add the remote:

git init
git remote add origin "$repo_name.git"

git init is safe and won't mess anything up if the local repo already exists.


Again, Hub recommended by hauleth does all this and more!

8 Responses
Add your response


Or you can use Hub which provide some more features.

over 1 year ago ·
Dushanbe red 500x500

Good to know! Thanks hauleth!

over 1 year ago ·

As already stated, Hub is a really great library for this kind of thing.

over 1 year ago ·

You can alias the hub command in your .dotfiles like so

hub_path=$(which hub)
if [[ -f $hub_path ]]
  alias git=$hub_path

that gives you the additional github commands

git pull-request   Open a pull request on GitHub
git fork           Make a fork of a remote repository 
                   on GitHub and add as remote
git create         Create this repository on GitHub and 
                   add GitHub as origin
git browse         Open a GitHub page in the default browser
git compare        Open a compare page on GitHub
over 1 year ago ·
54588 555132027835563 687647376 o

Some Shell Scripts for github

over 1 year ago ·

if not using Hub, but instead this method - you still need to remember to 'chmod +x script_name' the script file.

over 1 year ago ·
Dushanbe red 500x500

Great point tchaudhri, thanks!

over 1 year ago ·
Dushanbe red 500x500

Great point tchaudhri, thanks!

over 1 year ago ·
Filed Under