A project maintainer of an active open source project will learn new git
magic tricks. Every maintainer also has their own procedure of reviewing and testing pull requests. To do this, a maintainer may have an incantation of git
commands to set things up exactly the way they want.
But there is no easy, one-click way of doing this. Some commands must be run a specific order to pull a fresh local copy of a pull request. While reviewing several pull requests in a week, I realized a set of commands I was using frequently and converted them into these shell functions:
Pagure PR shell functions
Taken from jwflory/swiss-army. To use these, add them to your shell configuration. For example, for Bash this file is ~/.bashrc
.
# Pagure pull request, non-master branch
function pag_pull_nm {
git checkout master
git branch -D $2
git fetch origin pull/$1/head:$2
git checkout $2
}
# Pagure pull request, master branch
function pag_pull_m {
git checkout master
git branch -D pr-$1
git checkout -b pr-$1
git fetch origin pull/$1/head:master -f
git checkout master
git branch -D pr-$1
git checkout -b pr-$1
git checkout master
git reset --hard origin/master
git checkout pr-$1
}
Why are these necessary?
The first function, pag_pull_nm
, checks out a Pagure pull request where the contributor used a feature branch (i.e. a branch other than master
). This function is more straightforward and ensures you always have the latest version of a feature branch.
The second function, pag_pull_m
, checks out a Pagure pull request where the contributor used the master
branch of their fork to open the pull request. This function is tedious but it is a quick way to always pull out the latest changes for a pull request while also preserving the master
branch to always match what is on remotes/origin/master
.
What are your favorite workflow hacks?
Do you use some commands or shortcuts to improve a workflow? Have an insightful tip to share with other Fedora contributors? Let us know below in the comments!
Start the discussion by commenting on the auto-created topic at discussion.fedoraproject.org