Skip to content

Instantly share code, notes, and snippets.

@larsvilhuber
Forked from robwierzbowski/gitcreate.sh
Created March 26, 2018 18:26
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 larsvilhuber/2eb78f120bd784f2dfdcf2a7750e2353 to your computer and use it in GitHub Desktop.
Save larsvilhuber/2eb78f120bd784f2dfdcf2a7750e2353 to your computer and use it in GitHub Desktop.
A simple litte script. Create and push to a new github repo from the command line.
#!/bin/bash
# https://gist.github.com/robwierzbowski/5430952/
# Create and push to a new github repo from the command line.
# Grabs sensible defaults from the containing folder and `.gitconfig`.
# Refinements welcome.
# Gather constant vars
CURRENTDIR=${PWD##*/}
GITHUBUSER=$(git config github.user)
# Get user input
read "REPONAME?New repo name (enter for ${PWD##*/}):"
read "USER?Git Username (enter for ${GITHUBUSER}):"
read "DESCRIPTION?Repo Description:"
echo "Here we go..."
# Curl some json to the github API oh damn we so fancy
curl -u ${USER:-${GITHUBUSER}} https://api.github.com/user/repos -d "{\"name\": \"${REPONAME:-${CURRENTDIR}}\", \"description\": \"${DESCRIPTION}\", \"private\": false, \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}"
# Set the freshly created repo to the origin and push
# You'll need to have added your public key to your github account
git remote set-url origin git@github.com:${USER:-${GITHUBUSER}}/${REPONAME:-${CURRENTDIR}}.git
git push --set-upstream origin master
@larsvilhuber
Copy link
Author

Let's start with this.

Possibly incorporate

curl https://api.github.com/user/repos?access_token=myAccessToken -d '{"name":"REPO"}'

and

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO", "private":"true"}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment