Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
I needed to add a read-only collaborator to many repositories, and doing it via the website was really tedious
GITHUB_TOKEN=$(git config --global github.token) # I've defined an API token in my git config -- ymmv
GITHUB_USER="" # the collaborator
REPO_OWNER="" # the owner of the repos
REPOS="" # space-delimited list of repositories
PERMISSION="pull" # may be one of "admin", "push" (i.e., read/write -- default), or "pull" (i.e., read-only)
for REPO in ${REPOS} ; do
curl -X PUT -i -d '{ "permission": "'${PERMISSION}'" }' \
-H 'Accept: application/vnd.github.ironman-preview+json' \
-H "Authorization: token ${GITHUB_TOKEN}" \${REPO_OWNER}/${REPO}/collaborators/${GITHUB_USER}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.