Skip to content

Instantly share code, notes, and snippets.

@Ikhan
Created November 26, 2016 21:43
Show Gist options
  • Save Ikhan/feb9785847ef39df0032f257885e32da to your computer and use it in GitHub Desktop.
Save Ikhan/feb9785847ef39df0032f257885e32da to your computer and use it in GitHub Desktop.
Bash Script for creating github repos in terminal
github-create(){
repo_name=$1
dir_name=`basename $(pwd)`
invalid_credentials=""
if ["$repo_name" = ""]; then
echo "Repo Name (hit return to use) '$dir_name' ?"
read repo_name
fi
if ["$repo_name" = ""]; then
repo_name=$dir_name
fi
username=`git config user.username`
if [ "$username" = "" ]; then
echo "could not find the username, run 'git config --global github.user <username>'"
invalid_credentials=1
fi
token=`git config user.token`
if [ "$token" = "" ]; then
echo "could not find the token, run 'git config --global github.token <token>'"
invalid_credentials=1
fi
if [ "$invalid_credentials" '==' "1" ]; then
return 1
fi
echo -n "Creating GitHub Repos '$repo_name' ...."
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
echo " done."
echo -n "Pushing local code to remote ..."
git remote add origin [email protected]:$username/$repo_name.git > /dev/null 2>&1
git push -u origin master > /dev/null 2>&1
echo " done."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment