-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmergeTo.sh
50 lines (30 loc) · 797 Bytes
/
mergeTo.sh
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
# !/bin/bash
######################
# bash mergeTo.sh branch
# $1 - branch
######################
### variables
#
######################
CURRENT_BRANCH=$(git branch -vv | egrep "^\*" | awk '{ print $2 '})
if [ $1 ]; then
echo "Usage: $1 [branchname]"
TO_BRANCH=$!
else
TO_BRANCH=$(git branch -vv | egrep "^\*" | awk '{ print $2 '} | grep -Po '\w+' | head -1)
fi
ACTION=$(git branch -vv | egrep "^\*" | awk '{ print $4 '})
#######################
echo "tracking=$ACTION"
if [[ ! "$ACTION" =~ "origin" ]]; then
git checkout $TO_BRANCH
git rebase $CURRENT_BRANCH || exit 1
else
echo "This branch exists remotely, not rebasing"
fi
echo "Merge $TO_BRANCH into $CURRENT_BRANCH"
git checkout $CURRENT_BRANCH
git merge $TO_BRANCH || exit 1
echo
echo "Done"
exit 0