GitHub Repo creation via CLI

I am so excited after creating my first repository on github and successfully adding some test files to it from my local machine!
But due to my limited internet connection, I stumbled upon some diffulties.

It took me a lot of time and effort, and there were actually a few times when I thought that I wouldn’t be able to do it. It took me hours, and that is not how much it should have taken to just create a new repository.

So i had a huge challenge – How do I make more repositories and add my files to it without the need of a browser… mmmhhh after some vigorous Googling I came upon a simple command using ‘curl’.

Challenge was accepted and at 03:10am I was done creating a badass bash script that would not only create a github repository, it would initialise it and push my files to the repository with only a press of a button.

# -*- coding: utf-8 -*-
#  gitrep-create
#  The purpose of this script is to generate Github repository via cli instead of going to
#  Instructions for use: 
#  1. Install github [debian: sudo apt-get install -y git]
#  2. Fill in/Enter details
#     git config --global "Your Name"
#     git config --global ""
#  3. Generate token on > Settings > Applications > Generate token
#  Copyright 2015 Mpho Mphego <>
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  GNU General Public License for more details.
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.

function progress(){
echo -n "Please wait..."
while true
  echo -n "."
  sleep 1


# Note:
# To run from ~/.bash_profile, uncomment function below. and copy code to ~/.bash_profile
# else create script and place it in ~/bin.


  #trap "killall background" EXIT
  dir_name=`basename $(pwd)`
  username=`git config github.user` 
  token=`git config github.token` 

 if [ "$repo_name" = "" ]; then
    echo "Repo name (hit enter to use '$dir_name')?"
    read repo_name
  if [ "$repo_name" = "" ]; then

  if [ "$username" = "" ]; then
    echo "Could not find username, run 'git config --global github.user <username>'"

  echo Git Username: $username

  if [ "$token" = "" ]; then
    echo "Could not find token, run 'git config --global github.token <token>'"

  echo "Creating Github repository '$repo_name'"
  progress &

  $WGET -q --tries=10 --timeout=5 -O /tmp/ &> /dev/null
  if [ ! -s /tmp/ ];then
    echo "Check your Internet Connection."
    kill $myself &> /dev/null

    curl -u "$username:$token" -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
    kill $myself &> /dev/null
    echo -n "...done."
    echo " "
    echo "Enter 1 to Create new repository."
    echo "Enter 2 to Push on existing repository."
    read inputs
    if [ "$inputs" == "1" ]; then
      echo "Creating a new repository."
      echo "#" $repo_name >>
      git init
      echo " "
      git add
      echo " "
      git commit -m "first commit"
      echo " "
      git remote add origin$username/$repo_name.git
      echo " "
      git push -u origin master
      echo ".......Done........"
    if [ "$inputs" == "2" ]; then
      echo "Pushing an existing repository"
      git remote add origin$username/$repo_name.git
      echo " "
      git push -u origin master
      echo ".......Done........"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s