Last active
July 15, 2019 12:01
-
-
Save methodbox/2b18dbf5090d55a00d11901e6515cd33 to your computer and use it in GitHub Desktop.
Add a command "setup-repo" which remotely creates a GitHub repo for you and initializes Git for your local project.
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
#!/bin/bash | |
# GitHub API Token | |
GH_API_TOKEN='' | |
# GitHub User Name | |
GH_USER='' | |
# Variable to store first argument to setup-repo, the repo name. Will be used as GH repo name, too. | |
NEW_REPO_NAME=$1 | |
# Store current working directory. | |
CURRENT_DIR=$PWD | |
# Project directory can be passed as second argument to setup-repo, or will default to current working directory. | |
PROJECT_DIR=${2:-$CURRENT_DIR} | |
# GitHub repos Create API call | |
curl -H "Authorization: token $GH_API_TOKEN" https://api.github.com/user/repos -d '{"name": "'"${NEW_REPO_NAME}"'"}' | |
git init $PROJECT_DIR | |
# Initialize Git in project directory, and add the GH repo remote. | |
git -C $PROJECT_DIR remote add origin git@github.com:$GH_USEr/$NEW_REPO_NAME.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment