使用Shell建立GitHub倉庫

Github的代碼倉庫分爲2種類型:git

  • 用戶本身的代碼倉庫
  • 組織的代碼倉庫

下面就使用Shell腳本建立這2種類型的代碼倉庫,腳本以下github

建立用戶本身的代碼倉庫

#!/bin/bash

USER_NAME="[your username]"
PROJECT_NAME="[project name]"
PROJECT_DESCRIPTION="[project description]"

git init
git add .
git commit -m 'first commit'

curl -u $USER_NAME https://api.github.com/user/repos -d "{\"name\":\"$PROJECT_NAME\", \"description\": \"$PROJECT_DESCRIPTION\"}"

git remote add origin git@github.com:$USER_NAME/"$PROJECT_NAME".git
git push -u origin master

建立組織的代碼倉庫

#!/bin/bash

USER_NAME="[your username]"
ORGS_NAME="[orgination name]"
PROJECT_NAME="[project name]"
PROJECT_DESCRIPTION="[project description]"

git init
git add .
git commit -m 'first commit'

curl -u $USER_NAME https://api.github.com/orgs/"$ORGS_NAME"/repos -d "{\"name\":\"$PROJECT_NAME\", \"description\": \"$PROJECT_DESCRIPTION\"}"

git remote add origin git@github.com:$ORGS_NAME/"$PROJECT_NAME".git
git push -u origin master
相關文章
相關標籤/搜索