Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools

Fidel Torres
Fidel Torres
25,286 Points

Create a git repo from console using an Alias!!!

Hey there I want to create a git repo like this:

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'

But I want to do it using a alias in terminal(Ubuntu), like

alias newRepo = curl -u 'USER' https://api.github.com/user/repos -d '{"name":"$1"}';
                git remote add origin git@github.com:USER/$1.git;

So after in the terminal I type:

newRepo test

And it creates the repo and add the remote "origin"

2 Answers

Fidel Torres
Fidel Torres
25,286 Points

I have found a Solution in StackOverflow and also modified. So here I share which the TTH Community:

#!/bin/sh
#if your terminal whoami is the same user as github
user=$(whoami)
#otherwise
reponame="$1"
user=$2
if [ "$user" = "" ]; then
read -p "Enter Github username: " user
fi
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
fi
mkdir ./$reponame
cd $reponame
curl -u "$user" https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}"
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:T04435/$reponame.git
git push -u origin master

Then add alias to terminal if you are Ubuntu user add in ~/.bash_aliases otherwise find how in MacOS.

alias newRepo=/pathtothenewReposcript

Now you can use:

newRepo reponame

To create a:

  • New Folder
  • New README.md File & add it
  • Do The First Commit
  • Create the repo in Github
  • Add remote
  • And push all of it

In one sec

Hey sorry, wish I could help. Unfortunately my skills in ubuntu are limited.