how do I create github local and remote repository

Navigate to the user's root directory, and append the following codes to the fie .bash_profile

local_remote() {
    read -p "create local and remote git repository push all files in current directory? y/* " verify
    case "$verify" in
        yes|y)
            echo "..."
            ;;
        *)
            echo -n "you didn't enter y or n"
            exit
            ;;
    esac
    repo_name=$1
   
    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 local Github repository '$repo_name' ..."
    git init && git add . && git cm -m 'init commit' > /dev/null 2>&1
    echo " done."
   
    echo -n "Creating Github remote 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."
}

Every time you hit local_remote you'll create the local and remote git repository automatically. But notice the warning before you enter the first y or yes to verify. Once one have master bash programming, he can make his routine work much easy. I only have the basics of bash shell scripting only in hand and hope to know more and become a guru someday.  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值