LoginSignup
0
0

【GitHub】リポジトリを一括で非公開にする方法

Posted at

GitHubのリポジトリを一括で非公開にする方法を紹介します。リポジトリが少なければ手動で設定するのもありですが、数が多い場合は自動化したほうが楽です。最近はこういう系のスクリプトはChatGPTに聞けばすぐに出てくるので本当に便利です。

方法

以下のスクリプトにTOKENを入力して実行すると、GitHubの全リポジトリを非公開にできます。

#!/bin/bash
TOKEN=""

curl -s -H "Authorization: token $TOKEN" https://api.github.com/user/repos?visibility=public | jq -r '.[] | .url' | while read repo_url; do
    echo "非公開に設定: $repo_url"
    curl -s -X PATCH -H "Authorization: token $TOKEN" -d '{"private":true}' $repo_url
done

TOKENはhttps://github.com/settings/tokensから取得できます。

以下のようなrepoの権限を設定したTOKENを作成してスクリプトに入力してください。

スクリプトの内容としては、「GitHubのAPIを叩いてpublicになっているリポジトリのURLを取得→取得したURLを使って、リポジトリを非公開に設定」という流れになっています。

0
0
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
0
0