The git URL is then

Pull request refs

GitHub stores refs to pull requests on the original repository under refs/pull/<number>/head.

Therefore, if you want to get a pull request locally to try it out on a local branch you can do:

git fetch origin pull/<pr-number>/head
git checkout -b <local-branch-name> FETCH_HEAD

GitHub also offers the merge request directly at refs/pull/<pull-request-id>/merge.

Create branches for all pull requests on git fetch:

git config --local --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'

GitHub API v3 via cURL

GitHub has an HTTP REST API, which allows you to:

  • programmatically access and modify GitHub data

  • overcome certain web interface limitations.

    For example, on the web interface, you can only see up to 30 results for the starred repos of other people.

    With the API, you can get all of them at once and grep away by playing with per_page.

curl is a convenient way to use the API manually.



GET is the default request type:

curl$USER/starred?per_page=9999909 | grep -B1 "description" | less

Make a POST request with curl:

echo '{
  "text": "Hello world github/linguist#1 **cool**, and #1!",
  "mode": "gfm",
  "context": "github/gollum"
}' | curl --data @-

GitHub API Authentication

Many methods that take a user can use the authenticated user instead if present.

Basic with user password pair:

curl -u 'cirosantilli'


curl -u 'cirosantilli:password'

GitHub API OAuth

OAuth: generate a large random number called the access token. Which you can only get once.

There are two ways to get the token:

  • personal tokens, generated by a logged in user from:

    Useful if you need to generate only a few tokens for personal use.

  • application obtained token.

    A way for applications to interact with GitHub and obtain a token.

    User is first redirected to GitHub, inputs his password only there, and the token is sent back to the application.

    Useful if you are building an application that must interact with GitHub, and don’t want to store the user’s password.

    Each user gets a single token per application in case multiple token requests are made.

Tokens are safer than storing the password directly because:

  • it is possible to restrict what can be done with each token, thus increasing confidence users have on your application.
  • users can revoke tokens at any time, without changing their passwords.

Once you get the token, make an authenticated request with:



curl -H "Authorization: token $TOKEN"

Rate limiting

  • authenticated: 60 requests per hour
  • unauthenticated requests: 5000 requests per hour


Get given number of results. Default is 30. Allows you to beat web API limitations. List all starred repos of a user:

curl$USER/starred?per_page=9999909 | grep -B1 "description" | less

Get repo info

Lots of info:

curl -i$USER/repos

Create repo

curl -u "$USER" -d '{"name":"'$REPO'"}'

Repo name is the very minimal you must set, but you could also set other params such as:

curl -u "$USER" -d '{
   "name": "'"$REPO"'",
   "description": "This is your first repo",
   "homepage": "",
   "private": false,
   "has_issues": true,
   "has_wiki": true,
   "has_downloads": true

Its just JSON (remember, last item cannot end in a comma).

Delete repo


Careful, it works!


Powerful CLI interface:

gem install hub

Open URL of current branch / commit in browser:

hub browse

Create repository with same name as current dir:

hub create

Give a name and a description:

hub create name -d 'Description'