Skip to content

Instantly share code, notes, and snippets.

@JunkOSGitHub
Created January 19, 2016 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JunkOSGitHub/2b60eda998dd25810c09 to your computer and use it in GitHub Desktop.
Save JunkOSGitHub/2b60eda998dd25810c09 to your computer and use it in GitHub Desktop.
Git command to create a new repo on GitHub
#!/bin/bash
#
# Create a repo on github
#
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
exit 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 git@github.com:$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