Oct 24, 2015:  ~ 4 min read

Wrapping up the Pull Request from terminal

You might want to read the the first part and the second part, too.

During the weekend I rewrote a lot of the script, covering cases where the Pull Request failed, adding Fastlane automation and all around improvements.

The script has now 2 possible parameters, a different branch than development, and skip_deploy, in case we don't want to auto-run the fastlane command. Comments explaining the flow, as usual:

perform_pull_request() {
  # Default to not skipping deploy.
  # Default to development branch as base.
  yellow "Pushing $branch_to_push to remote..."
  git push origin "$branch_to_push":"$branch_to_push"
  # If the first or second parameter is "sd",
  # we are going to skip running fastlane.
  if [ "$1" == "$sd" ] || [ "$2" == "$sd" ]; then
  if [ $? -eq 0 ]; then
    green "Push to remote successful."
  # If the first or second parameter is not empty *and* it's different than "sd",
  # it means we asked for a new branch as base.
  if [ -n "$1" ] && [ "$1" != "$sd" ]; then
  elif [ -n "$2" ] && [ "$2" != "$sd" ]; then
  yellow "Creating Pull Request to $branch: \"$(formatted_git_branch)\"..."
  pr_url=$(hub pull-request -b "$branch" -m "$(formatted_git_branch)")
  if [ $? -eq 0 ]; then
    # If we didn't run the fastlane command, it usually means we just want
    # to merge it, so let's open the GitHub page.
    if [ $skip_deploy == true ]; then
      open "$pr_url"
      # If we did run the fastlane command, it usually means
      # the build is going to Hockey for QA to test, but
      # why not copy the Pull Request URL, just in case?
      green "Pull Request opened at ${yellow}$(echo $pr_url | pbcopy)$(pbpaste), ${green}and its URL was copied to your clipboard."
  elif [ $? -eq 1 ]; then
    red "Something went wrong, opening GitHub's Pull Requests page..."
    open "https://github.com/[...]/pulls"
  if [ $skip_deploy == false ]; then
    yellow "Handing over to Fastlane now..."
    fastlane hockey scheme:debug

Also, the Alfred workflow changed slightly, to compensate for these changes:

cd ~/path/to/project && gitpr {query}

I'm pretty sure I could improve this a lot, but it's the first bash script I have a go at, so if you have any suggestions, please let me know @rolandleth.

Subscribe to my monthly newsletter.
No spam, unsubscribe at any time.