Skip to content

Instantly share code, notes, and snippets.

@farfanoide
Last active August 29, 2015 13:58
Show Gist options
  • Save farfanoide/10146013 to your computer and use it in GitHub Desktop.
Save farfanoide/10146013 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Script to create a github repo and [if possible] add it as a remote
# on the current one
#
# ------------------------------------------------------------------------------
# Author
# -------
#
# * Farfanoide (https://github.com/farfanoide)
#
# ------------------------------------------------------------------------------
[ $# -eq 0 ] && echo "Usage: $(basename $0) <repository_name> [username]" && exit 1
repo_name=$1; shift
[ $# -gt 0 ] && username=$1 || username=$(git config github.user)
endpoint='https://api.github.com/user/repos'
repo_url="$(curl -u ${username} ${endpoint} -d "{\"name\":\"${repo_name}\"}" | grep ssh_url | cut -d\" -f4 )"
origin="$(git remote -v | grep origin)"
if [ ! -z "${repo_url}" -a -z "${origin}" ]; then
git remote add origin $repo_url
fi
# TODO: git init if not exists, ask for remote name if origin exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment