Skip to content

Instantly share code, notes, and snippets.

@jbsmith86
Last active December 7, 2019 06:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbsmith86/8551663 to your computer and use it in GitHub Desktop.
Save jbsmith86/8551663 to your computer and use it in GitHub Desktop.
This will create a local git repo inside your current directory and a repo on github and then push it to github. Paste this into a new file (i.e. generate_github_repo.sh) inside your project directory . Run the following: chmod +x ./generate_github_repo.sh This only needs to be done once. now you can start the script with: ./generate_github_repo…
#!/bin/bash
#Replace the empty constants below if you don't want to be prompted for credentials
USERNAME=""
PASSWORD=""
if [ "$USERNAME" == "" ]; then
echo -n "Enter your Github username and press [ENTER]: "
read USERNAME
fi
echo -n "Enter a project name for your new Github repository and press [ENTER]: "
read REPO
if [ "$PASSWORD" != "" ]; then
CREDSHASH=$USERNAME":"$PASSWORD
else
CREDSHASH=$USERNAME
fi
REPOHASH='{"name":"'$REPO'"}'
echo "contacting Github API..."
curl -u $CREDSHASH https://api.github.com/user/repos -d $REPOHASH > /dev/null
FILENAME=`basename $0`
if grep -q "$FILENAME" .gitignore; then
echo "gitignore file already patched"
else
echo "$FILENAME" >> .gitignore
fi
echo "making local repo..."
if [ ! -d ".git" ]; then
git init
git add -A .
git commit -m "Initial commit"
fi
echo "adding remote..."
git remote add origin git@github.com:$USERNAME/$REPO.git
git push -u origin master
@elliotec
Copy link

This is the best. Github should adopt this

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