Skip to content

Instantly share code, notes, and snippets.

@John-Almardeny
Last active June 15, 2018 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save John-Almardeny/b595dacdc31e84012045486b39f69236 to your computer and use it in GitHub Desktop.
Save John-Almardeny/b595dacdc31e84012045486b39f69236 to your computer and use it in GitHub Desktop.
Create Github repository locally and remotely at the same time, also push the local one to the remote repo.
#!/bin/bash
#https://gist.github.com/John-Almardeny/b595dacdc31e84012045486b39f69236
#Create Github repository locally and remotely at the same time
#also push the local one to the remote repo.
#first check if curl is installed
#if not -> intstall it
if [ ! $(which curl) ];then
echo -e "\n*****************************************"
echo "curl not found, starting to install it..."
echo -e "*****************************************\n"
sudo apt-get install curl
echo -e "\n\n"
fi
#ask for repo name and github user name
echo -e "Enter New Repository Name: "
read repname
echo -e "Enter your Github Username: "
read user
#create the remote repo
#abort if there is error (usually cuz of bad credintials!)
response="$(curl -u $user https://api.github.com/user/repos -d "{\"name\":\"$repname\"}")"
if [[ $response = *"Bad credentials"* ]]; then
echo -e "\nIncorrect Username or/and Password!\n"
exit 0
fi
echo -e "\n****Remote $repname Repo Created Successfully!****\n"
#create local repo and move to its directory
# add REAdME file and push it to the remote one
git init $repname
mkdir $repname
cd $repname
touch README
git add README
git commit -m "initial"
echo -e "\n****Local $repname Repo Created Successfully!****\n"
git remote add origin git@github.com:$user/$repname.git
git push origin master
echo -e "\nDone!\n"
@John-Almardeny
Copy link
Author

John-Almardeny commented Jan 27, 2018

What Does This File Do For Me?
It contains a Bash Script to automate and accelerate your work on GitHub, specifically: creating remote repository using your bash terminal instead of using the GitHub GUI on their Website. You then will have the created repo both locally and remotely.

How To Use?

  1. Move the create_repo.sh file to the directory you want your local repository to be created in, for e.g.:
cd ~/github
mv /from_create_repo.sh_path .

note the dote(.) above, it's necessary as it means "to the current directory i.e. github dir in our example"

  1. In order to make the file executable, Issue this command :
    sudo chmod +x git_setup.sh

  2. Run the file like this: ./create_repo.sh

  3. You will be asked to enter:

    • The Repository Name
    • Your Github User Name
    • Your Github Password

Enjoy!

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