Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple litte script. Create and push to a new github repo from the command line.
#!/bin/bash
# https://gist.github.com/robwierzbowski/5430952/
# Create and push to a new github repo from the command line.
# Grabs sensible defaults from the containing folder and `.gitconfig`.
# Refinements welcome.
# Gather constant vars
CURRENTDIR=${PWD##*/}
GITHUBUSER=$(git config github.user)
# Get user input
read "REPONAME?New repo name (enter for ${PWD##*/}):"
read "USER?Git Username (enter for ${GITHUBUSER}):"
read "DESCRIPTION?Repo Description:"
echo "Here we go..."
# Curl some json to the github API oh damn we so fancy
curl -u ${USER:-${GITHUBUSER}} https://api.github.com/user/repos -d "{\"name\": \"${REPONAME:-${CURRENTDIR}}\", \"description\": \"${DESCRIPTION}\", \"private\": false, \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}"
# Set the freshly created repo to the origin and push
# You'll need to have added your public key to your github account
git remote set-url origin git@github.com:${USER:-${GITHUBUSER}}/${REPONAME:-${CURRENTDIR}}.git
git push --set-upstream origin master
@ltrainpr

This comment has been minimized.

Show comment Hide comment
@ltrainpr

ltrainpr Aug 3, 2013

I've been looking to automate creating Github repos from the command line and setting an alias. I'm new to scripts and bash programming in general. How do I implement this script? Do I just clone this gist from the terminal? Is there anything else I need to do?

ltrainpr commented Aug 3, 2013

I've been looking to automate creating Github repos from the command line and setting an alias. I'm new to scripts and bash programming in general. How do I implement this script? Do I just clone this gist from the terminal? Is there anything else I need to do?

@softvar

This comment has been minimized.

Show comment Hide comment
@softvar

softvar Aug 23, 2013

Python wrapper for Github gists - simplegist
On github - https://github.com/softvar/simplegist

  • Creating gists returning the url, script and clone link for copy-paste purpose
  • Checkout one's gists - Name(s), Description and Content
  • Edit and Delete a gist
  • Search GitHub user's gist - fork, star and unstar them
  • List-all comments of any gist, make/edit a comment on a gist, delete a comment

softvar commented Aug 23, 2013

Python wrapper for Github gists - simplegist
On github - https://github.com/softvar/simplegist

  • Creating gists returning the url, script and clone link for copy-paste purpose
  • Checkout one's gists - Name(s), Description and Content
  • Edit and Delete a gist
  • Search GitHub user's gist - fork, star and unstar them
  • List-all comments of any gist, make/edit a comment on a gist, delete a comment
@softvar

This comment has been minimized.

Show comment Hide comment
@softvar

softvar Aug 23, 2013

@itrainpr simply copy the contents to a bash file or simply clone this gist and run this bash script which which automatically ask u to enter your username, reponame and Repo-Description. It will also prompt you for your github password in order to push it directly to github.com without opening and creating using browser.

softvar commented Aug 23, 2013

@itrainpr simply copy the contents to a bash file or simply clone this gist and run this bash script which which automatically ask u to enter your username, reponame and Repo-Description. It will also prompt you for your github password in order to push it directly to github.com without opening and creating using browser.

@xixixao

This comment has been minimized.

Show comment Hide comment
@xixixao

xixixao Dec 15, 2013

The read syntax doesn't work for me on OS X.

Use a fork instead!

xixixao commented Dec 15, 2013

The read syntax doesn't work for me on OS X.

Use a fork instead!

@aberezin

This comment has been minimized.

Show comment Hide comment
@aberezin

aberezin Apr 4, 2014

Thanks @xixisao for the fork. You can also rewrite the bash reads like
read -p "Enter the foo value" foo

aberezin commented Apr 4, 2014

Thanks @xixisao for the fork. You can also rewrite the bash reads like
read -p "Enter the foo value" foo

@robwierzbowski

This comment has been minimized.

Show comment Hide comment
@robwierzbowski

robwierzbowski Jun 13, 2014

defunkts' hub is 100000* better than this. Go there!

Owner

robwierzbowski commented Jun 13, 2014

defunkts' hub is 100000* better than this. Go there!

@bogas04

This comment has been minimized.

Show comment Hide comment
@bogas04

bogas04 Nov 16, 2015

I'm using

#Usage: gcreate userName repoName "Description if any"
gcreate () { 
  curl -u $1 https://api.github.com/user/repos -d "{\"name\": \"$2\", \"description\": \"$3\"}"
}

You can put it in .bash_profile / .bashrc and simply use gcreate

bogas04 commented Nov 16, 2015

I'm using

#Usage: gcreate userName repoName "Description if any"
gcreate () { 
  curl -u $1 https://api.github.com/user/repos -d "{\"name\": \"$2\", \"description\": \"$3\"}"
}

You can put it in .bash_profile / .bashrc and simply use gcreate

@sv7-harun

This comment has been minimized.

Show comment Hide comment
@sv7-harun

sv7-harun Feb 23, 2017

hi guys
I am using curl to create remote repository in GITHUB but it is getting error. Can anyone help me out which path i need to pass during curl command execution like GITHUB Url or github organization Url . Please it is urgent

hi guys
I am using curl to create remote repository in GITHUB but it is getting error. Can anyone help me out which path i need to pass during curl command execution like GITHUB Url or github organization Url . Please it is urgent

@sv7-harun

This comment has been minimized.

Show comment Hide comment
@sv7-harun

sv7-harun Feb 23, 2017

when I am using curl below error i am getting

<title>405 Not Allowed</title>

405 Not Allowed

when I am using curl below error i am getting

<title>405 Not Allowed</title>

405 Not Allowed

@LolnationCH

This comment has been minimized.

Show comment Hide comment
@LolnationCH

LolnationCH Dec 16, 2017

@bogas04 That's exactly what have trying to do the past 15 minutes, tks!

@bogas04 That's exactly what have trying to do the past 15 minutes, tks!

@bpJedisim

This comment has been minimized.

Show comment Hide comment
@bpJedisim

bpJedisim May 7, 2018

Did not work for me, I created a bash function with name gcreate using above contents, it gives following error:

$ gcreate
# now nothing appears, it does not ask for repo name, if I type repo name "hello" and press enter, it gives this error:
-bash: read: `REPONAME?New repo name (enter for github):': not a valid identifier

Did not work for me, I created a bash function with name gcreate using above contents, it gives following error:

$ gcreate
# now nothing appears, it does not ask for repo name, if I type repo name "hello" and press enter, it gives this error:
-bash: read: `REPONAME?New repo name (enter for github):': not a valid identifier
@bpJedisim

This comment has been minimized.

Show comment Hide comment
@bpJedisim

bpJedisim May 7, 2018

@bogas04, the function is simple and appealing, but, however, unfortunately, did not work.

$ gcreate bpJedisim repoName "Description if any"
Enter host password for user 'bpJedisim':
curl: (35) error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

@bogas04, the function is simple and appealing, but, however, unfortunately, did not work.

$ gcreate bpJedisim repoName "Description if any"
Enter host password for user 'bpJedisim':
curl: (35) error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment