A neat
gitscript written in PHP to easily locally pull a PR from Github
In a nutshell, to locally test PR #1337, just do:
git pr 1337This will
- creates a new branch named
pr-1337and switch to it - pulls whatever repo/branch has been submitted as the PR on Github
This will be equivalent to :
git checkout -b pr-1337
git pull https://github.com/SOMEDUDE/SOMEFORK.git SOMEBRANCHgit pr comes with handy options. git pr -h prints the following help :
Usage: git pr [OPTION] [PR_NUM]
Startup:
-l | --list list all pull requests of the current repo
-v | --version display the version number
-h | --help display the help message
Pull options:
-n | --nocommit pull given PR but do not commit changes
-t | --test test the script, do not actually pull the PR
Branch name options:
-b | --branch <branch> custom local PR branch name (defaults to "pr-[PR_NUM]")
-s | --suggest suggest a custom local branch name based on the PR title
By default, the local branch you're pulling will be named pr-<NUMBER>, using the Github PR number.
Quick and handy, but when you're working with pr-4102, pr-4107 and fix-issue-1337, it becomes
cumbersome to remember which is which.
To avoid this, you can manually specify a branch name with -b or --branch:
git pr -b fix/some-issue 1337
Even lazier, let the script suggest a local branch name, using a short version of the actual branch title.
Say PR #1337 has the title Add a SQL index for faster lookups !, using the -s or --suggest option:
$ git pr -s 1337
Suggested branch name: add-sql-index-faster-lookups
Press enter to use this name, or type a new one:
With a gigantic pull request that changes a lot of files, it can be easier to review changes, since modified files are marked (if using a tool with icon overlays, like TortoiseGit)
From now on you can review, of course modify, and then commit changes, or simply git merge --abort if proposed changes are not suitable.
Add this to your git config (eg ~/.gitconfig)
[alias]
pr = "!php /full/path/to/ozh_git_pr.php"Do whatever the hell you want to do with it
