Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script creates a new repo on github.com, then pushes to it the local repo from the current directory. Fork of https://gist.github.com/robwierzbowski/5430952/. Some of Rob's lines just didn't work for me, and I made it more verbose while fixing. UPDATE 2017-06-30. No longer needed by Xcode users because this capability is built into Xcode 9 :)
#!/bin/bash
# This script create a new repo on github.com, then pushes the local repo from the current directory to the new remote.
# It is a fork of https://gist.github.com/robwierzbowski/5430952/. Some of Rob's lines just didn't work for me, and to fix them I needed to make it more verbose so that a mere electrical engineer could understand it.
# This script gets a username from .gitconfig. If it indicates that your default username is an empty string, you can set it with
# git config --add github.user YOUR_GIT_USERNAME
# Gather constant vars
CURRENTDIR=${PWD##*/}
GITHUBUSER=$(git config github.user)
# Get user input
echo "Enter name for new repo, or just <return> to make it $CURRENTDIR"
read REPONAME
echo "Enter username for new, or just <return> to make it $GITHUBUSER"
read USERNAME
echo "Enter description for your new repo, on one line, then <return>"
read DESCRIPTION
echo "Enter <return> to make the new repo public, 'x' for private"
read PRIVATE_ANSWER
if [ "$PRIVATE_ANSWER" == "x" ]; then
PRIVACYWORD=private
PRIVATE_TF=true
else
PRIVACYWORD=public
PRIVATE_TF=false
fi
REPONAME=${REPONAME:-${CURRENTDIR}}
USERNAME=${USERNAME:-${GITHUBUSER}}
echo "Will create a new *$PRIVACYWORD* repo named $REPONAME"
echo "on github.com in user account $USERNAME, with this description:"
echo $DESCRIPTION
echo "Type 'y' to proceed, any other character to cancel."
read OK
if [ "$OK" != "y" ]; then
echo "User cancelled"
exit
fi
# Curl some json to the github API oh damn we so fancy
curl -u $USERNAME https://api.github.com/user/repos -d "{\"name\": \"$REPONAME\", \"description\": \"${DESCRIPTION}\", \"private\": $PRIVATE_TF, \"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 add origin https://github.com/$USERNAME/$REPONAME.git
git push -u origin master
@shinokada

This comment has been minimized.

Copy link

@shinokada shinokada commented Dec 24, 2013

I used two-factor authentication. Any idea to add this too?

@jerrykrinock

This comment has been minimized.

Copy link
Owner Author

@jerrykrinock jerrykrinock commented Sep 9, 2014

Wow. I didn't know github was doing two-factor. Sorry, I have no plans to do that.

@drzax

This comment has been minimized.

Copy link

@drzax drzax commented Jul 3, 2017

Any more info about xcode integration? I can't find any docs on it.

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