Skip to content

Instantly share code, notes, and snippets.

@eddiemoya
Last active May 19, 2017 18:11
Show Gist options
  • Save eddiemoya/ad4285b2d8a6bdabf432 to your computer and use it in GitHub Desktop.
Save eddiemoya/ad4285b2d8a6bdabf432 to your computer and use it in GitHub Desktop.
Fast forward merges one branch into another without having to checkout either - fails if the second parameter is not fast-forwardable.
#!/bin/bash
# usage:
# git-merge-ff-only.sh master develop
# Will only merge develop into master if its fast-forwardable.
merge_into=$1;
merge_from=$2;
git merge-base --is-ancestor $merge_into $merge_from;
is_ffable=$?
if [ $is_ffable == 0 ]; then
git update-ref refs/heads/$merge_into $merge_from;
echo "[$merge_from] has been fast-forward merged into [$merg_into]";
else
echo "[$merge_from] can NOT be fast-forward merged into [$merged_into]";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment