Skip to content

Instantly share code, notes, and snippets.

@joshdmiller
Created September 13, 2013 19:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshdmiller/6554896 to your computer and use it in GitHub Desktop.
Save joshdmiller/6554896 to your computer and use it in GitHub Desktop.
A little helper for creating new Git repositories with GitHub.
#!/bin/bash
###
# Usage: github.sh my-repo-name
###
# Configuration
username="joshdmiller"
readme="README.md"
commit_msg="chore(*): initial commit"
# The repo name passed in.
repo=$1
# A convenience method for error reporting and exiting.
function fail () {
echo "$0" 1>&2 && exit 1
}
# Create the new directory.
test -d $repo && fail "Directory already exists."
mkdir $repo || fail "Could not create new directory."
cd $repo
# Create a new repo.
git init .
touch $readme
git add $readme
git commit -m "$commit_msg"
# Create the remote repository and push.
git remote add origin git@github.com:$username/$repo.git
curl -u "$username" https://api.github.com/user/repos -d "{\"name\":\"$repo\"}"
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment