Created
March 29, 2010 23:30
-
-
Save bmizerany/348549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
API="http://github.com/api/v2/json/repos/create" | |
function die() { | |
echo >&2 "$1" | |
exit 1 | |
} | |
function usage() { | |
die "Usage: $0 repo-name [-p]" | |
} | |
# name is required | |
[ $# -lt 1 ] && usage | |
name=$1 | |
public=0 | |
while getopts p o; do | |
case "$o" in | |
p) | |
public=1 | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
# Grab credentials | |
user=$(git config github.user) | |
token=$(git config github.token) | |
if [ -z "$user" -o -z "$token" ]; then | |
die 'You need to set github.user and github.token; see `git help config`' | |
fi | |
# Make the request | |
curl -F "login=$user" \ | |
-F "token=$token" \ | |
-F "name=$name" \ | |
-F "public=$public" \ | |
"$API" 2>&1 1> /dev/null | |
[ ! -d .git ] && exit | |
# clone/push url | |
git="[email protected]:$user/$name.git" | |
echo "Adding remote github for $git" | |
git remote add github "$git" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment