Skip to content

Instantly share code, notes, and snippets.

@spidergears
Last active July 11, 2016 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spidergears/66e8059e5648d58a8d264ec190ee19b3 to your computer and use it in GitHub Desktop.
Save spidergears/66e8059e5648d58a8d264ec190ee19b3 to your computer and use it in GitHub Desktop.
Bash script to create empty github repository
git-create(){
repo_name=$1
dir_name=`basename $(pwd)`
if [ "$repo_name" = "" ]; then
echo -n "Repo name [$dir_name]?: "
read repo_name
fi
if [ "$repo_name" = "" ]; then
repo_name=$dir_name
fi
username=`git config user.name`
if [ "$username" = "" ]; then
echo -n "Could not find username, run 'git config --global user.name <username>'"
return 1
fi
token=`git config user.token`
if [ "$token" = "" ]; then
echo -n "Could not find token, run 'git config --global user.token <token>'"
return 1
fi
echo -n "Creating Github repository '$repo_name'..."
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
echo "Done."
echo -n "Adding remote..."
git remote add origin git@github.com:$username/$repo_name.git
echo "Done."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment