Skip to content

Instantly share code, notes, and snippets.

@s-aska
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/e1c74bc3b6d6770b1ce8 to your computer and use it in GitHub Desktop.
Save s-aska/e1c74bc3b6d6770b1ce8 to your computer and use it in GitHub Desktop.
簡易に git merge する奴
#!/bin/bash
# Usage: git-merge.sh [branch]
# ex: git-merge.sh master
set -ue
# set -e ... 途中でエラーが発生したら止める
# set -u ... 未定義の変数を参照したらエラー
if [[ $# == 0 ]];
then
echo "Usage: git-merge.sh [branch]"
echo " ex: git-merge.sh master"
exit 1
fi
TO="$1"
FROM=`git rev-parse --abbrev-ref HEAD`
function confirm() {
read -p "$@? [y/n] " y
if [ ! "x$y" = "xy" ];
then
echo "Not Confirmed."
exit 1
fi
return 0
}
function echo_and_exec() {
echo
echo "> $@"
$@
}
confirm "git merge $FROM => $TO"
echo_and_exec git checkout $TO
echo_and_exec git pull
echo_and_exec git merge $FROM
echo
confirm "git push origin $TO"
echo_and_exec git push origin $TO
echo_and_exec git checkout $FROM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment