GithubなどのクラウドサービスへGitレポジトリを利用する時、ついつい画面を利用していました。最近ふと思いました、クラウド側のGitレポジトリもコマンドベースで作成できないかと。開発者向けのWEBサービスでは大概REST APIを提供しているので、今回そちらを利用してみました。手っ取り早いBasic認証を扱っています。詳細なAPI仕様については参考をご覧ください。
Github
どのAPIもEnter host password for user '%username':と聞かれるのでパスワードを入力すること。
レポジトリ登録は以下の通り。
curl -u "%username" -X POST -H "Content-type: application/json" -d '{"name":"%sample_repo", "private":true}' https://api.github.com/user/repos
登録後手持ちのレポジトリにプッシュ先として登録しておく。
git remote add origin git@github.com:%username/%sample_repo.git
レポジトリ情報参照は以下の通り。
curl -u "%username" https://api.github.com/repos/%username/%sample_repo
レポジトリ削除は以下の通り。
curl -u "%username" -X DELETE https://api.github.com/repos/%username/%sample_repo
Bitbucket Cloud
レポジトリ登録は以下の通り。%repo_flagは小文字の英数字のみなので要注意。レポジトリ名は%nameへ入力しよう。
curl -u %username:%password -X POST -H "Content-type: application/json" -d '{"scm":"git", "name":"%name", "is_private":true, "fork_policy":"no_forks"}' https://api.bitbucket.org/2.0/repositories/%username/%repo_flag
登録後手持ちのレポジトリにプッシュ先として登録しておく。
git remote add origin git@bitbucket.org:%username/%sample_repo.git
レポジトリ情報参照は以下の通り。
curl -u %username:%password https://api.bitbucket.org/2.0/repositories/%username/%sample_repo
レポジトリ削除は以下の通り。
curl -u %username:%password -X DELETE https://api.bitbucket.org/2.0/repositories/%username/%sample_repo