Helpful Scripts

This page helps users with some scripts to do their daily work.

GitHub

Retrieve a pull request locally

Just put the following script in a file called git-pr in your ~/bin folder. If bin does not exist, create it and add it to your PATH var (depending on your shell environment, you have to add it to different files. for e.g. zsh you just need to add it to the .zshrc file and the existing PATH variable).

#!/bin/bash
#
# Git enhancement - Pull Request
# This script will fetch a pull request locally based on its number
# and rebases the work onto the latest master branch.
#
# Usage: git pr <pull-request-number>
#
# Author: Patrice Bouillet (NovaTec Consulting GmbH)
# Version: 2015-06-01
if [ ! -n "$1" ]
then
        echo "Usage: git pr <pull-request-number>"
        exit 1
fi
if ! echo $1 | grep --quiet "^[0-9]*$"; then
        echo "Usage: git pr <pull-request-number>"
        exit 1
fi
git fetch origin
if ! git diff --no-ext-diff --quiet --exit-code; then
        echo "# To utilize this script, changes to files must be commited/stashed/reverted etc."
        echo "# =============================================================================="
        git status
        exit 1
fi
git fetch origin refs/pull/$1/head && git checkout FETCH_HEAD && git rebase -f origin/master

After this script is created, it should be available via calling git pr:

# the number after git pr defines the pull request to retrieve
# the following will retrieve the pull request 1
git pr 1

No local work will be deleted or overwritten due to this script. It will warn if anything would happen and before the execution, the workspace needs to be cleaned.