Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First, you need to generate a personal access token (PAT) on your GitHub account that has permissions to manage team memberships. Then, you can use the following Bash script to automate the process:

#!/bin/bash

# Set variables
ORG_NAME="your-organization-name"
TEAM_NAME="your-team-name"
PAT="your-personal-access-token"

# Read a file containing a list of usernames (one per line)
while read -r USERNAME; do
    # Add the user to the team
    curl -X PUT -H "Authorization: token $PAT" "https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_NAME/memberships/$USERNAME"
done < usernames.txt

Replace your-organization-name, your-team-name, your-personal-access-token, and usernames.txt with your own values. The usernames.txt file should contain a list of usernames (one per line) that you want to add to the team.

Save the script to a file (e.g. add-team-members.sh) and make it executable using chmod +x add-team-members.sh. Then, run the script with ./add-team-members.sh to add the users to the team.