Sign in

Git Scripts

Here are some useful scripts to automate some of our workflows when using Git. Store these scripts in a directory that you have in your $PATH and use them as subcommands in git e.g. git merge-pull-request.

git-create-pull-request

Creates a new branch for your pull request and pushes that branch to the remote repository.

git create-pull-request DDI-XX-my-feature
#!/usr/bin/env bash

set -e

branch=${1}
master="master"

echo "Creating pull request ${branch} from ${master}"

git checkout $master
git pull --rebase
git checkout -b $branch
git push --set-upstream origin $branch

git-update-pull-request

Updates the local and remote version of your branch with changes from the remote master.

# With the branch checked out
git update-pull-request

# Without the branch checked out
git update-pull-request DDI-XX-my-feature
#!/usr/bin/env bash

set -e

current_branch=$(git rev-parse --abbrev-ref HEAD)
branch=${1:-$current_branch}
master="master"

echo "Updating pull request ${branch} from ${master}"

git checkout $master
git pull --rebase
git checkout $branch
git rebase $master
git push --force

git-merge-pull-request

Merges a branch into master branch and updates the remote master branch. Deletes the local and remote pull request branch if merging was uploaded. This makes sure you merge pull request correctly without using the GitHub merge button (that button often creates a merge commit).

# With the branch checked out
git merge-pull-request

# Without the branch checked out
git merge-pull-request DDI-XX-my-feature
#!/usr/bin/env bash

set -e

current_branch=$(git rev-parse --abbrev-ref HEAD)
branch=${1:-$current_branch}
master="master"

echo "Merging pull request ${branch} into ${master}"

git checkout $master
git pull --rebase
git merge --ff-only $branch
git push
git branch -d $branch
git push origin :$branch