-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpush.sh
78 lines (57 loc) · 1.53 KB
/
push.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# !/bin/bash
######################
# bash push.sh -type remote branch
# $1 - -type (-c = common (push into origin remote and current branch) | -s = specify (push into some remote and branch))
# $2 - remote
# $3 - branch
######################
### variables
#
PBRANCH=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//')
if [ -n $1 ]; then
if [ $1 == '-c' ]; then
BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
REMOTE="origin"
elif [ $1 == '-s' ]; then
if [ -n $2 ] || [ -n $3 ]; then
echo ""
echo "You didn't set up remote/origin"
read -p "Set up remote name: " REMOTE
echo ""
read -p "Set up branch name: " BRANCH
echo ""
else
BRANCH=$3
REMOTE=$2
fi
else
echo ""
exit 0
fi
else
echo ""
exit 0
fi
#push process
git add .
read -p "Do you want to specify message for commit?(yes / no)?" answ
case $answ in
[Yy]* ) read -p "Commit message: " COMMIT; ;;
[Nn]* ) COMMIT="Commit at $(date +"%r %a %d %h %y")";;
* ) echo "Please answer yes or no";;
esac
echo ""
echo "Commit message will be $COMMIT";
echo ""
git commit -am "$COMMIT"
git push --set-upstream $REMOTE $BRANCH 2>&1
refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
if [ -z "PBRANCH" ]; then
PBRANCH="master"
fi
refs="$PBRANCH...$BRANCH"
echo "Pushed a branch '$BRANCH' remotely"
echo ""
echo "Pushed to"
echo $(git remote show $REMOTE -n | grep Push | awk '{ print $3 }')
exit 0