Hacker News new | ask | show | jobs
by fishywang 1485 days ago
I have this script:

    $ cat ~/bin/git-pr 
    #!/bin/sh
    
    if [ $# -lt 1 ]; then
      exit -1
    fi
    
    git fetch origin refs/pull/$1/head:pr/$1
So I can run `git pr <number>` to get `pr/<number>` branch created locally that I can checkout to.
3 comments

Also there is github cli for checking out PR

     $ gh pr checkout {<number> | <url> | <branch>}
You can also configure git to fetch the GitHub PR branches[0]. Add this line to your .git/config:

    fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
This has to be done in each repository you have checked out locally, but maybe it is possible to also have this done globally. But I never tried to do it.

[0] http://tiborsimko.org/github-local-handling-of-pull-requests...

You can add to the set of refs that git pulls (via remote.origin.refs); so for me it's `git checkout pr/123/head` (or /merge) instead, without creating a local branch that you need to delete later.