How to fetch Github pull request as local branch

Github pull requests are the mechanism by which contributors submit code for review and subsequent merging to a Github branch. It can sometimes be useful to grab a pull request as a branch in your local repository. This can be useful for example to diff with one of your local branches or to merge with one of your local branches.

To fetch a Github pull request, note down its number XYZ. Use this command to fetch it to a new local branch:

$ git fetch origin pull/XYZ/head:new_local_branchname

The pull request is now available locally as the branch new_local_branchname.

Reference: https://help.github.com/en/articles/checking-out-pull-requests-locally

Advertisements

Slow speed on git clone

Sometimes when I have to clone a huge repository from Github, I find that the fetch speed can be extremely slow (KB/s).

There are two tricks I try for a quick cloning:

  • Kill the command and try again. Do this a few times, see if you can get a faster connection. This works most of the times.

  • Fetch only the latest revision first and then fetch the rest:

$ git clone --depth=1 git@github.com:joe/hello-world.git
$ cd hello-world
$ git fetch --unshallow

Tried with: Git 1.9.1 and Ubuntu 14.04

Octotree extension for Chrome

If you use Github a lot for browsing code, then you will find it irritating that it does not have a project explorer. That is, you want to explore the directory structure of a project and view the source code of the files by clicking through the directory structure. This is a standard feature in all IDEs and most editors.

Octotree provides just this useful feature to Github. This Chrome extension can be installed from here. Its source code is here.

On any Github project page, it gives a sidebar that shows the directory structure and you can click through to view the source code of any file in the project.

Tried with: Octotree 1.3.0, Chrome 35.0.1916.153 and Ubuntu 14.04

How to use Punchcard extension of Mercurial

Punchcard of a Mercurial repository
Punchcard of a Mercurial repository

One of the coolest feature of Github is the calendar chart that is shows for your contributions. You can get a similar chart for any Mercurial repository on your computer using the Punchcard extension.

  • First clone the Punchcard repository in a suitable directory:
$ hg clone https://bitbucket.org/birkenfeld/hgpunchcard
  • Modify your hgrc by adding these lines:
[extensions]
hgpunchcard = /path/to/hgpunchcard.py
  • To generate the punchcard for a repository, try this command from inside any of its directories:
$ hg punchcard

This saves a file named punchcard.png that a chart of your commits to this repository, as shown above.

Tried with: Mercurial 2.8.2 and Ubuntu 14.04