Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri
Last active August 29, 2015 13:55
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 ahmedelgabri/8728023 to your computer and use it in GitHub Desktop.
Save ahmedelgabri/8728023 to your computer and use it in GitHub Desktop.

Read first

I have a local file called ~/.zstuff that I load all ENV variables that is not supposed to be public like $GITHUB_TOKEN in it & I source this file inside my main .zshrc file. The $GITHUB_USER can be added to the same file or your normal .zshrc file since it not a senstive information.

The .zstuff Shoudn't be public or part of your .dotfiles repo.

# New Github repo
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
if [[ "$GITHUB_USER" = "" ]]; then
echo "Could not find username, add 'export GITHUB_USER=<username>'"
invalid_credentials=1
fi
if [[ "$GITHUB_GLOBAL_TOKEN" = "" ]]; then
echo "Could not find token, add 'export GITHUB_GLOBAL_TOKEN=<token>'"
invalid_credentials=1
fi
if [[ "$invalid_credentials" == "1" ]]; then
return 1
fi
echo -n "Creating Github repository '$repo_name' ..."
curl -u "$GITHUB_USER:$GITHUB_GLOBAL_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:$GITHUB_USER/$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