Git is a great version control system and Github is superb hosting service for git based repositories.
Github provides a nice web interface to create (blank) repositories at the start of project. But why visit github.com to create a blank repository, so here’s a simple bash script to make this simple task even simpler.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git-create(){ | |
repo_name=$1 | |
dir_name=`basename $(pwd)` | |
if [ "$repo_name" = "" ]; then | |
echo -n "Repo name [$dir_name]?: " | |
read repo_name | |
fi | |
if [ "$repo_name" = "" ]; then | |
repo_name=$dir_name | |
fi | |
username=`git config user.name` | |
if [ "$username" = "" ]; then | |
echo -n "Could not find username, run 'git config --global user.name <username>'" | |
return 1 | |
fi | |
token=`git config user.token` | |
if [ "$token" = "" ]; then | |
echo -n "Could not find token, run 'git config --global user.token <token>'" | |
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 "Adding remote..." | |
git remote add origin git@github.com:$username/$repo_name.git | |
echo "Done." | |
} |
Script is based on Curl and GithubApi.
Add this to bash_profile and reload it. Done 🙂
Use git-create
to summon .
Be sure to configure github username and access_token in global git configure file.
Hint:
git config --global user.name <username>
git config --global user.token <access_token>