Skip to content

Instantly share code, notes, and snippets.

@methodbox
Last active July 15, 2019 12:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save methodbox/2b18dbf5090d55a00d11901e6515cd33 to your computer and use it in GitHub Desktop.
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.
#!/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