-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-update
46 lines (36 loc) · 845 Bytes
/
git-update
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
#
checkIfGitRepo() {
git rev-parse --is-inside-work-tree > /dev/null 2>&1
GIT_CHECK=$?
if [[ GIT_CHECK -ne 0 ]]; then
echo "This is not a valid git repo! Exiting..."
exit 1
fi
}
fetchLatest() {
echo "FETCHING LATEST"
git fetch --prune --all --progress
}
updateBranch() {
BRANCH_NAME=$1
echo "---"
echo "Updating branch: '$BRANCH_NAME'"
CHECKOUT_OUT=`git checkout $BRANCH_NAME`
if [[ "$CHECKOUT_OUT" != *"branch is up to date"* ]]; then
git merge
fi
}
DIR=${PWD}
checkIfGitRepo
MASTER_BR=$(git config --get gitflow.branch.master)
DEV_BR=$(git config --get gitflow.branch.develop)
if [[ -z $MASTER_BR || -z $DEV_BR ]]; then
echo "Branchs information not set. Use 'git flow init' command to initalize git flow";
exit 2
fi
set -e
fetchLatest
updateBranch $MASTER_BR
updateBranch $DEV_BR
echo "=== DONE ==="