Skip to content

Instantly share code, notes, and snippets.

@cognivator
Created September 4, 2018 22:47
Show Gist options
  • Save cognivator/b67ab73840253bceb79efe54627d9f6d to your computer and use it in GitHub Desktop.
Save cognivator/b67ab73840253bceb79efe54627d9f6d to your computer and use it in GitHub Desktop.
SourceTree Custom Action to FETCH the selected branch
#!/bin/bash
set -e
set -o pipefail
unset fetch_git_branch
fetch_git_branch=`git name-rev --refs=heads/* --name-only $1 | grep -oE '^[^~]+'`
echo fetching... $fetch_git_branch
git fetch origin $fetch_git_branch:$fetch_git_branch
unset fetch_git_branch

For use in Atlassian SourceTree as a custom action.

Usage

Select a branch in SourceTree, then invoke the custom action that calls this script. The selected branch will be fetched and fast-forwarded.

Installation:

  1. Download the accompanying git_fetch_by_hash shell script into a location on your PATH. Ensure it is executable with chmod u+x git_fetch_by_hash
  2. In Atlassian, open Preferences and create a new Custom Action:
  • set Script to run: to git_fetch_by_hash
  • set Parameters: to $SHA
  • (optional) set a keyboard shortcut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment