public
Last active

A simple litte script. Create and push to a new github repo from the command line.

  • Download Gist
gitcreate.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/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

I've been looking to automate creating Github repos from the command line and setting an alias. I'm new to scripts and bash programming in general. How do I implement this script? Do I just clone this gist from the terminal? Is there anything else I need to do?

Python wrapper for Github gists - simplegist
On github - https://github.com/softvar/simplegist

  • Creating gists returning the url, script and clone link for copy-paste purpose
  • Checkout one's gists - Name(s), Description and Content
  • Edit and Delete a gist
  • Search GitHub user's gist - fork, star and unstar them
  • List-all comments of any gist, make/edit a comment on a gist, delete a comment

@Itrainpr simply copy the contents to a bash file or simply clone this gist and run this bash script which which automatically ask u to enter your username, reponame and Repo-Description. It will also prompt you for your github password in order to push it directly to github.com without opening and creating using browser.

The read syntax doesn't work for me on OS X.

Use a fork instead!

Thanks @xixisao for the fork. You can also rewrite the bash reads like
read -p "Enter the foo value" foo

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.