Search code examples
githubgithub-api

Add member to GitHub repo using CLI or REST


I have a private repo that belongs to my organization on GitHub. Is there any way to add members to this repo (or to a team) using GitHub CLI or any other API that allows me to perform this action programmatically?


Solution

  • Add collaborator to rope by CLI:

    # GitHub CLI api
    # https://cli.github.com/manual/gh_api
    
    gh api \
      --method PUT \
      -H "Accept: application/vnd.github+json" \
      -H "X-GitHub-Api-Version: 2022-11-28" \
      /repos/OWNER/REPO/collaborators/USERNAME \
      -f permission='triage'
    

    https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#add-a-repository-collaborator