add merge-into to merge two branches quickly

This commit is contained in:
spacewander 2015-03-10 18:14:56 +08:00
parent d690268b43
commit d94663312f

34
bin/git-merge-into Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
current_branch() {
git rev-parse --abbrev-ref HEAD
}
usage() {
echo "Usage: git merge-into [src] dest [--ff]"
}
cur_branch=$(current_branch)
if [ "${!#}" == '--ff' ]; then
case $# in
2 ) # dest --ff
git push "$(git rev-parse --show-toplevel)" "$cur_branch":"$1";;
3 )
git push "$(git rev-parse --show-toplevel)" "$1":"$2";;
* )
usage
esac
else
case $# in
1 )
git checkout "$1"
git merge "$cur_branch" "$1" && git checkout "$cur_branch"
;;
2 )
git checkout "$2"
git merge "$1" "$2" && git checkout "$cur_branch"
;;
* )
usage
esac
fi