Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active September 1, 2015 17:50
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/11371574 to your computer and use it in GitHub Desktop.
Save domenic/11371574 to your computer and use it in GitHub Desktop.
.bashrc with GitHub PR function
pr () {
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1 --force
git checkout -b pr/$1 origin/pr/$1
git rebase master
git checkout master
git merge pr/$1 --ff-only
}
@domenic
Copy link
Author

domenic commented Apr 28, 2014

You can now CD into a directory containing a checked-out Git repo and type pr 42 to pull down the contents of PR #42 and put it on top of master.

If the PR was already on top of master, then pushing this will automatically close the PR as "merged." If not, then the PR will remain open, and you'll want to close it with a comment like "merged in deadb33f."

@domenic
Copy link
Author

domenic commented Apr 28, 2014

Note that on Macs by default .bashrc doesn't run. See http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically

@domenic
Copy link
Author

domenic commented Sep 1, 2015

For merging your own PRs, or in general any PR that uses a branch on the main repo instead of a fork, you can try:

mypr () {
  git checkout $1
  git rebase master
  git push origin $1 --force
  git checkout master
  git merge $1 --ff-only
}

Usage:

$ mypr selectors-attribute-values # rebases, force-pushes to update origin version, and merges to local master
$ git push # pushes local master to origin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment