git-pr: painless small pull requests


git-pr: painless small pull requests

In CodeRefinery, we teach the benefit of small changes via pull requests in order to have better collaboration and review. But, when the changes get small enough, the time it takes to run the commands and open the pull requests begins to get annoying. I looked around for other tools that could make this faster, but wasn't quite satisfied with anything. So, I slowly started making something that evolved into git-pr, https://github.com/NordicHPC/git-pr.

Let's talk about how it works.

Making a change

First, git-pr will help you to make the new feature branch. git pr branch $branch_name willcreate a new feature branch off of the upstreamdefault branch and check it out for you. You might want to git fetch first. Make your commits off of this branch.

One trick I use is to write the first commit's message like I would write the pull request description. I decided it's usually not worth writing a separate description for the pull request itself. Perhaps there is some advantage to including the PR message in the git history itself, too.

Then, to push the pull request, I use git pr open. This will push the current branch, and open a pull request on both Github and Gitlab. It will pop up an editor pre-seeded with the commit's message for you to further edit. Once you save and close, the pull request is made.

One thing that git-pr will do is figure out the upstream and your local copy by yourself. Default upstream goes in priority order upstreamorigin, Default personal fork goes in the order localoriginupstream, so no matter if you first clone the upstream, or your own fork, you can always add the other with only one command and have it auto-detected with no renaming.

git pr prune will remove all merged branches both locally and on the remote (possibly dangerous!).

Various git pr fetch* commands will fetch pull requests into a local pr/NNN branch.

There are various other small useful things, with it, but this is the main part.

These are only shorthands for things you can easily do with other git commands, but they save you time. It gets me closer to the ideal of making many small pull requests.

About git-pr

You can find it at https://github.com/NordicHPC/git-pr - it is a single shell script to copy to your path.

It's beta-quality software: it is used by me and a few others all the time, but there will almost certainly be issues as others start using it. Send issues and PRs!

It supports both Github and Gitlab, though Gitlab support is less well tested.

There is a lot of prior art on different pieces here, there isn't much in git-pr that is completely new - In particular, the GitHub command line interface has come out since then and has some overlap. You can see other options in the git-pr README.


Funding

CodeRefinery is a project within the Nordic e-Infrastructure Collaboration (NeIC). NeIC is an organisational unit under NordForsk.

Privacy

Privacy policy

Follow us

Contact

support@coderefinery.org