Skip to content

Instantly share code, notes, and snippets.

@tilap
Last active May 14, 2016 18:34
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 tilap/2168b2afa7ad75d5a4f74da42011f1a2 to your computer and use it in GitHub Desktop.
Save tilap/2168b2afa7ad75d5a4f74da42011f1a2 to your computer and use it in GitHub Desktop.
BASH: Command to create a git repo from CLI
# USAGE: githubrepo name-of-the-repo
githubrepo() {
USERNAME=tilap
if [ $# -ne 1 ]; then
echo "You must provide the name of the repo"; \
exit; \
fi
local REPO=$1
echo "Create repo $REPO on github";
local RESPONSE=$(curl --write-out "%{http_code}\n" --silent --output /dev/null -i -u $USERNAME -d "{\"name\": \"$REPO\", \"auto_init\": true}" https://api.github.com/user/repos) if [ $RESPONSE -eq 201 ]; then
echo "Repository created on github"; \
git init; \
git remote add origin "git@github.com:$USERNAME/$REPO.git"; \
else
echo "Error while creating the repo, received a $RESPONSE code"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment