Skip to content

Instantly share code, notes, and snippets.

@joshbuker
Last active May 18, 2018 21:25
Show Gist options
  • Save joshbuker/c112df84d006bded3a3f5d5d53abb685 to your computer and use it in GitHub Desktop.
Save joshbuker/c112df84d006bded3a3f5d5d53abb685 to your computer and use it in GitHub Desktop.
Helpful bash functions for Git
git_pr() {
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] ; then
echo "Missing required arguments:"
echo "1 - origin/upstream (remote where PR exists, not the fork)"
echo "2 - pull request ID (e.g. '42' without quotation)"
echo "3 - local branch to fetch onto (must not already exist)"
else
if git fetch $1 pull/$2/head:$3 ; then
git checkout $3
else
echo "Failed to fetch pull request $2"
fi
fi
}
git_fancy_merge() {
if [ -z "$1" ] ; then
echo "Missing required arguments:"
echo "1 - <file>"
else
fullpath=$1
directory=$(dirname "$fullpath")
file=$(basename "$fullpath")
extension="${file#*.}"
filename="${file%%.*}"
echo "Creating reference files using:" $fullpath
echo "Common:" $directory/$filename.common.$extension
git show :1:$fullpath > $directory/$filename.common.$extension
echo "Ours: " $directory/$filename.ours.$extension
git show :2:$fullpath > $directory/$filename.ours.$extension
echo "Theirs:" $directory/$filename.theirs.$extension
git show :3:$fullpath > $directory/$filename.theirs.$extension
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment