Last active
August 29, 2015 14:21
-
-
Save Luminus/b0ff0c754c8c5fe6c780 to your computer and use it in GitHub Desktop.
Create a GitHub repo from Terminal. Paste this in ~/.bash_profile or if like me you use zsh, paste it in ~/.zshrc
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
github-create() { | |
repo_name=$1 | |
dir_name=`basename $(pwd)` | |
if [ "$repo_name" = "" ]; then | |
echo "Repo name (hit enter to use '$dir_name')?" | |
read repo_name | |
fi | |
if [ "$repo_name" = "" ]; then | |
repo_name=$dir_name | |
fi | |
username=`git config github.user` | |
if [ "$username" = "" ]; then | |
echo "Could not find username, run 'git config --global github.user <username>'" | |
invalid_credentials=1 | |
fi | |
token=`git config github.token` | |
if [ "$token" = "" ]; then | |
echo "Could not find token, run 'git config --global github.token <token>'" | |
invalid_credentials=1 | |
fi | |
if [ "$invalid_credentials" == "1" ]; then | |
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 "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
For some reason, this kept throwing a "Not Found" error. I eventually just went with dumping the code into a text-file named github-create under ~/bin/ and running chmod a+x on it.
If you're going to do this, remember to remove the "github-create() {" at the top and the final curly brace.