mnwcog
Last Updated: February 25, 2016
·
20.54K
· 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"

#!/bin/sh

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

curl -u 'your_github_username' https://api.github.com/user/repos -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:

PATH=$PATH:~/bin
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 "https://github.com/your_github_username/$repo_name.git"

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

Enjoy!

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

8 Responses
Add your response

6820
Me

Or you can use Hub which provide some more features.

over 1 year ago ·
6826
Dushanbe red 500x500

Good to know! Thanks hauleth!

over 1 year ago ·
6915
F9961873414a964cb8aa6d81aa2e2293

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

over 1 year ago ·
6971
E6b625008c816ab3d8d742cc3eddbb00

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

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

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 ·
7035
54588 555132027835563 687647376 o

Some Shell Scripts for github
https://github.com/rShetty/Scriptomaniac

over 1 year ago ·
7044
920336c9691d56f5048491399e5c2ded

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 ·
7078
Dushanbe red 500x500

Great point tchaudhri, thanks!

over 1 year ago ·
7079
Dushanbe red 500x500

Great point tchaudhri, thanks!

over 1 year ago ·
Filed Under