Last Updated: September 09, 2019
·
968
· walidvb

Create github repo from Terminal

UPDATE: just brew install hub: http://hub.github.com/

Small snippet I found, simply added init of a local git repo.
Add the function to your ~/.profile, or save its core in a file in your $PATH, et voilà!

github-create() {
  repo_name=$1
  if ! [ -d ".git" ]; then
    echo "Creating local git repo"
    git init > /dev/null 2>&1
    echo $repo_name >> README.md
    echo "==============" >> README.md
    git add README.md > /dev/null 2>&1
    git commit -a -m "first commit" > /dev/null 2>&1
  fi
  dir_name=`basename $(pwd)`

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

  if [ "$repo_name" = "" ]; then
    repo_name=$dir_name
  fi

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

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

  if [ "$invalid_credentials" == "1" ]; then
    return 1
  fi

  echo -n "Creating Github repository '$repo_name' ..."
  curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}' > /dev/null 2>&1
  echo " done."

  echo -n "Pushing local code to remote ..."
  git remote add origin git@github.com:$username/$repo_name.git > /dev/null 2>&1
  git push -u origin master > /dev/null 2>&1
  echo " done."
}

Source: http://viget.com/extend/create-a-github-repo-from-the-command-line

2 Responses
Add your response

So it turns out some great people created a full program: http://hub.github.com/

over 1 year ago ·
over 1 year ago ·