-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-merge-branch
executable file
·56 lines (42 loc) · 1.2 KB
/
git-merge-branch
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
#!/bin/sh
set -e
function usage() {
bold=$(tput bold)
normal=$(tput sgr0)
cat << EOF
${bold}NAME${normal}
git-merge-branch - Merge the current branch into the master branch
${bold}SYNOPSIS${normal}
git merge-branch
EOF
}
# actually parse the options and do stuff
while [[ $1 = -?* ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
*) ;;
esac
shift
done
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
fi
upstream=$(git rev-parse --abbrev-ref @{upstream} 2>/dev/null)
echo '[INFO] Syncing remotes and branches'
hub sync
echo "[INFO] git checkout $defaultBranch"
git checkout $defaultBranch
echo "[INFO] Merge branch: ${currentBranch}"
git merge --no-ff --no-edit ${currentBranch}
git push $upstream $defaultBranch
echo "[INFO] Delete local and remote branch '$currentBranch' from '${upstream}'"
# Delete the remote branch if it lives in origin
git push --delete $upstream ${currentBranch}
# Delete the pull request branch locally
git branch -d ${currentBranch}