Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFidel Torres
25,286 PointsCreate 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
25,286 PointsI 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
Alex Cevallos
16,551 PointsHey sorry, wish I could help. Unfortunately my skills in ubuntu are limited.