Last active
December 7, 2019 06:47
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]:$USERNAME/$REPO.git | |
git push -u origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the best. Github should adopt this