Created
April 13, 2020 13:13
-
-
Save abdullahicyc/11af7122dd42ee4c83781ce4cd803853 to your computer and use it in GitHub Desktop.
github.sh
This file contains 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/sh | |
# | |
# github.sh | |
# - create a new repository in Github | |
# | |
# Copyright (C) 2015 Kenju - All Rights Reserved | |
# https://github.com/KENJU/git_shellscript | |
# get user name | |
username=`git config github.user` | |
if [ "$username" = "" ]; then | |
echo "Could not find username, run 'git config --global github.user <username>'" | |
invalid_credentials=1 | |
fi | |
# get repo name | |
dir_name=`basename $(pwd)` | |
read -p "Do you want to use '$dir_name' as a repo name?(y/n)" answer_dirname | |
case $answer_dirname in | |
y) | |
# use currently dir name as a repo name | |
reponame=$dir_name | |
;; | |
n) | |
read -p "Enter your new repository name: " reponame | |
if [ "$reponame" = "" ]; then | |
reponame=$dir_name | |
fi | |
;; | |
*) | |
;; | |
esac | |
# create repo | |
echo "Creating Github repository '$reponame' ..." | |
curl -u $username https://api.github.com/user/repos -d '{"name":"'$reponame'"}' | |
echo " done." | |
# create empty README.md | |
echo "Creating README ..." | |
echo "# $reponame" > README.md | |
echo " done." | |
# push to remote repo | |
echo "Pushing to remote ..." | |
git init | |
git add -A | |
# set my personal email instead of work email | |
git config user.email "abdullahicyc@gmail.com" | |
git commit -m "initial commit" | |
git remote rm origin | |
git remote add origin https://github.com/$username/$reponame.git | |
git push -u origin master | |
echo " done." | |
# opening in a browser | |
open https://github.com/$username/$reponame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment