Wednesday, January 22, 2014

Set up an active GitHub repo with a single bash command

There should never be any barrier between thinking of something and putting it on GitHub.

With that in mind, here's a very short bash function + alias I use to get a repo up as quickly as possible.

# github
function new_github_repo(){
    if [ -z "$1" ]
        then
            echo "Usage: github [name]"
        else
            USER='YOUR_GIT_USERNAME'
            curl -u "$USER" https://api.github.com/user/repos -d '{"name":"'$1'"}'
            cd ~
            mkdir $1
            cd $1
            touch README.md
            git init
            git add -A
            git commit -am "Initial commit."
            git remote add origin git@github.com:$USER/$1.git
            git push origin master
    fi
}
alias github='new_github_repo'

No comments: