-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-merge-dev
executable file
·65 lines (51 loc) · 1.37 KB
/
git-merge-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
set -e
function usage() {
bold=$(tput bold)
normal=$(tput sgr0)
cat << EOF
${bold}NAME${normal}
git-merge-dev - Merge the current branch into a development or integration branch
${bold}SYNOPSIS${normal}
git merge-dev <TARGET-BRANCH>
EOF
}
# actually parse the options and do stuff
while [[ $1 = -?* ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
*) ;;
esac
shift
done
targetBranch=$1
if [ -z "${targetBranch}" ]; then
echo "Error: Must specify a target branch"
usage
exit 1
fi
currentBranch=$(git rev-parse --abbrev-ref HEAD)
defaultBranch=$(git remote show origin | awk '/HEAD branch/ {print $NF}')
if [ "${currentBranch}" == "${defaultBranch}" ]; then
echo "Error: Branch currently set to Default Branch: ${defaultBranch}"
usage
exit 1
fi
upstream=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null | awk -F'/' '{print $1}')
if [ -z "${upstream}" ]; then
upstream=origin
fi
echo "[INFO] pushing ${currentBranch} to ${upstream}"
git push $upstream $currentBranch
echo '[INFO] Syncing remotes and branches'
hub sync
echo "[INFO] git checkout ${targetBranch}"
git checkout ${targetBranch}
echo "[INFO] Merge branch: ${currentBranch} into ${targetBranch}"
git merge --no-ff --no-edit ${currentBranch}
git push $upstream $targetBranch
echo "[INFO] Checkout original branch: $currentBranch"
git checkout $currentBranch