2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

REST APIからクラウドへGitレポジトリ作成を行う

2
Last updated at Posted at 2016-10-31

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

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?