Skip to content

Instantly share code, notes, and snippets.

@niradler
Created July 21, 2019 21:46
Show Gist options
  • Save niradler/cd55879b004ebd73b33cded8fe75f947 to your computer and use it in GitHub Desktop.
Save niradler/cd55879b004ebd73b33cded8fe75f947 to your computer and use it in GitHub Desktop.
create new github repo with bash. ./create-new-repo.sh {repo name} [path]
#!/bin/bash
# https://medium.com/better-programming/create-github-repos-remotely-25153a6e6890
# 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 [email protected]:$GH_USEr/$NEW_REPO_NAME.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment