-
Notifications
You must be signed in to change notification settings - Fork 1
/
catch_up.sh
42 lines (37 loc) · 972 Bytes
/
catch_up.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
#!/bin/bash
# exit when any command fails
set -e
while getopts bf option
do
case "${option}"
in
b) BRANCH=1;;
f) FORK=1;;
esac
done
echo "================================================================="
echo "=== catchup to remote master no options ==="
echo "-b parameter for catching up to upstream branch for forked repo = $BRANCH"
echo "-f parameter for catching up to upstream master for forked repo = $FORK"
echo "================================================================="
if [[ $BRANCH ]]
then
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
git fetch upstream
git checkout master
git merge upstream/master
git push
git checkout $branch_name
git merge master
elif [[ $FORK ]]
then
git fetch upstream
git checkout master
git merge upstream/master
git push
else
git checkout master
git pull
fi