p-robot
p-robot

Reputation: 4894

How does one add a collaborator in Github using the command line?

I'd like to know how to add a collaborator to a private repo in GitHub using the command line. I'm on a mac (10.6.8) or Ubuntu 11.04.

Upvotes: 6

Views: 8459

Answers (3)

Sindre
Sindre

Reputation: 300

According to this doc you can use the Github CLI to add Colleborators.

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' 

Then you can build a script around this to add multiple collaborators in one go or to multiple repos. (The github web UI does not support this I believe)

Upvotes: 5

Diomedes
Diomedes

Reputation: 938

Neither github gem nor hub (these are two popular command line interfaces for github) provide functionality to add a collaborator to a repo. This means that the only way to add a collaborator from the command line is to use curl and accessing the github api directly (the github api allows for collaborator addition/removal/listing).

Here is how for example I added a collaborator to my own repo, together with github's response when I did that (the response isn't very helpful - but it is what you get on success):

> curl -i -u "my_user_name:my_password" -X PUT -d '' 'https://api.github.com/repos/my_gh_userid/my_repo/collaborators/my_collaborator_id'

HTTP/1.1 204 No Content
Server: nginx
Date: Sun, 25 Nov 2012 06:45:10 GMT
Connection: keep-alive
Status: 204 No Content
X-RateLimit-Limit: 5000
X-GitHub-Media-Type: github.beta
X-RateLimit-Remaining: 4999
X-Content-Type-Options: nosniff
Cache-Control: 

The relevant add collaborator API page is here and this is the page that explains how to use curl to use the github API from the command line in general. Hope this helps.

FYI, I found your answer when I was looking to do exactly what you were asking - and couldn't find a satisfactory answer (besides using curl...). I plan to ask the maintainer of "hub" to see why he has not add that functionality to his tool.

Upvotes: 10

Yogi patel
Yogi patel

Reputation: 61

You can create a token for them - take a look at https://help.github.com/articles/creating-an-oauth-token-for-command-line-use.

It's usually a lot easier to do it through the web interface though.

Upvotes: 2

Related Questions