Skip to content

Instantly share code, notes, and snippets.

@s-aska s-aska/git-merge.sh
Last active Aug 29, 2015

Embed
What would you like to do?
簡易に 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
You can’t perform that action at this time.