Last active
September 19, 2017 00:07
-
-
Save jasonwarta/7cca7b0eaf5e2229b69e15bf4eb924cb to your computer and use it in GitHub Desktop.
function that creates a git repo using the git API
This file contains 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
git-init () { | |
# function that creates a git repo using the git API | |
# this function requires the following env variables to be set: | |
# GIT_USERNAME with your git username | |
# GIT_TOKEN with your git personal access token | |
# | |
# these are used when calling the api to create a new repo | |
# place the function code and env vars in your .bashrc or .profile | |
# interact with the function with the following syntax | |
# git-init <repo_name> [<public||private>] | |
# git-init -h or --help will print the above message | |
if [ $1 == '-h' ] || [ $1 == '--help' ]; then | |
echo "Usage:" | |
echo " git-init <repo_name> [<public||private>]" | |
return | |
fi | |
repo_name="$1" | |
if [ -z "$2" ] || [ $2 == 'public' ]; then | |
private="false" | |
elif [ "$2" = "private" ]; then | |
private="true" | |
fi | |
curl -u "$GIT_USERNAME:$GIT_TOKEN" -d "{ \"name\": \"${repo_name}\", \"private\": ${private}, \"has_issues\": true, \"has_projects\": false, \"has_wiki\": false }" -H "Content-Type: application/json" -X POST https://api.github.com/user/repos 2>&1 1>/dev/null && | |
echo "Creating \"$repo_name\"" && | |
mkdir "$repo_name" && cd "$repo_name" && | |
echo "# $repo_name" > README.md && | |
git init && | |
git add README.md && | |
git commit -m "first commit" && | |
git remote add origin "git@github.com:$GIT_USERNAME/$repo_name.git" && | |
git push -u origin master | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment