Skip to content

Instantly share code, notes, and snippets.

@loganhasson
Created June 4, 2014 19:39
Show Gist options
  • Save loganhasson/3bdd673d9a5c66c53f6b to your computer and use it in GitHub Desktop.
Save loganhasson/3bdd673d9a5c66c53f6b to your computer and use it in GitHub Desktop.
better command line github repo creation

Add to your .bash_profile:

# A function to create new github repos from the command line
# USE: gh repo-name

function gh () {
  curl -s -u '<githubusername>:<githubapitoken>' https://api.github.com/user/repos -d "{\"name\":\"$1\"}" | sed -n '/"ssh_url"/p' | gawk 'match($0, /:{1}\s"(.*)"/, ary) {print ary[1]}' | pbcopy
}

To create repos on an organization (Defaults to private...public creation doesn't work right now):

# A function to create new github repos for a specific organization
# USE: gho repo-name org-name

function gho () {
  if [ -n "$3" ]; then                                                      
    private=$("false")
  else
    private=$("true")
  fi 
  curl -s -u '<githubusername>:<githubapitoken>' https://api.github.com/orgs/"$2"/repos -d "{\"name\":\"$1\",\"private\":\"$private\"}" | sed -n '/"ssh_url"/p' | gawk 'match($0, /:{1}\s"(.*)"/, ary) {print ary[1]}' | pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment