Last active
February 4, 2019 16:12
-
-
Save planetceres/32ed36f6e0619242956e1b492f97df82 to your computer and use it in GitHub Desktop.
Create new Github repo from command line
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 | |
git_create () { | |
# Based on https://gist.github.com/robwierzbowski/5430952/ | |
# Get defaults | |
CURRENTDIR=${PWD##*/} | |
GITHUBUSER=$(git config github.user) | |
# Get user input | |
read -p "New Repo Name [$CURRENTDIR]: " REPONAME | |
REPONAME=${REPONAME:-$CURRENTDIR} | |
read -p "Github Username [$GITHUBUSER]: " USER | |
USER=${USER:-$GITHUBUSER} | |
read -p "Description [None]: " DESCRIPTION | |
read -n 1 -p "Create repo as private (y/n)? " private | |
echo $private | |
if [ "$private" != "${private#[Nn]}" ] ;then | |
PRIVATE=false | |
else | |
PRIVATE=true | |
fi | |
echo "Creating github.com/$USER/$REPONAME" | |
echo "Decription: $DESCRIPTION" | |
echo "Private: $PRIVATE" | |
echo "" | |
read -p "Press [Enter] to create repo.." cont | |
# Use Github API to create repo | |
curl -u $USER https://api.github.com/user/repos -d "{\"name\": \"$REPONAME\", \"description\": \"$DESCRIPTION\", \"private\": $PRIVATE, \"has_issues\": true, \"has_downloads\": true, \"has_wiki\": false}" | |
# Use ssh to set origin | |
git remote set-url origin [email protected]:$USER/$REPONAME.git | |
echo "Repo created successfully, and origin set to [email protected]:$USER/$REPONAME.git" | |
read -n 1 -p "Push local commits to remote origin (y/n)? " push | |
echo "" | |
if [ "$push" != "${push#[Nn]}" ] ;then | |
echo "Not pushing local commits to remote. Process complete." | |
else | |
git push --set-upstream origin master | |
echo "Local commits pushed to remote. Process complete." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes you have ssh keys set up with GitHub. If not, just replace remote with
https
equivalent.To use:
git_create
function in your~/.bash_profile
or~/ .bashrc
filesource ~/.bash_profile
orsource ~/ .bashrc
cd $HOME/<path_to_your_project>
git_create
from command line and follow the prompts