-
Notifications
You must be signed in to change notification settings - Fork 2
/
github.sh
136 lines (121 loc) · 3.11 KB
/
github.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#! /bin/bash
### Git automation script for automating git clone, push and pull ###
### Created by PIYUSH-MISHRA-00 ###
while :
do
echo
echo "Which Git operation you want to perform ?"
echo
echo "GitHub username: $username"
echo "Local repository name: $local_repo"
echo "Remote repository name: $remote"
echo "The default branch you want to work with: $branch"
echo "GPG key value: $GPG"
echo
echo -e "\t(0) Configure (configures the script for continuous uses)"
echo -e "\t(1) Clone"
echo -e "\t(2) Pull"
echo -e "\t(3) Push"
echo -e "\t(4) Exit"
echo -n "Enter your choice [0-4]: "
read choice
case $choice in
0) echo "Enter the values for future use of the script..."
echo
echo "Enter GitHub username: "
read username
export username
echo "Your username is: $username"
echo
echo "Local repository name: "
read local_repo
export local_repo
echo "Your local repository name is: $local_repo"
echo
echo "Remote repository name: "
read remote
export remote
echo "Remote repository name is: $remote"
echo
echo "The default branch you want to work with: "
read branch
export branch
echo "The default branch you want to work with: $branch"
echo
echo "GPG key value is: $GPG"
echo
echo "GPG key id for signed commits(leave blank if you don't want signed commits)"
read GPG
export GPG
echo "GPG key value is: $GPG"
echo
;;
1) echo "Cloning from GitHub"
echo
echo "Enter the repository https url: "
read clone_url
git clone $echo $clone_url;;
2) echo "Pulling from GitHub"
echo
echo "Enter the repository https url: "
read pull_url
echo
echo $pull_url
echo
while :
do
echo "Which type of Git Pull you want ?"
echo -e "\t(1) Merge (the default strategy)"
echo -e "\t(2) Rebase"
echo -e "\t(3) Fast-forward only"
echo -e "\t(4) Return to main menu"
echo -n "Enter your choice [1-4]: "
read pull_choice
case $pull_choice in
1)
git config pull.rebase false
git pull $echo "$pull_url";;
2)
git config pull.rebase true
git pull $echo "$pull_url";;
3)
git config pull.ff only
git pull $echo "$pull_url";;
4)
break
;;
*)
echo "Invalid operation"
;;
esac
done
;;
3) echo "Pushing to GitHub"
declare -A map
map[$echo"$local_repo"] = $echo"$remote"
git config --global user.name $echo"$username"
git config --global user.signingkey $echo$GPG
git init
git add .
echo "Enter Commit message: "
read message
git commit -m $echo "$message"
echo "Enter Tag name: (Press enter if you want to skip the tag name)"
read tag
echo "Enter Tag message: (Press enter if you want to skip the tag message)"
read tag_message
git tag -a $echo$tag -m "$echo$tag_message"
git tag -n
for i in "${!map[@]}"
do
git remote add $i https://github.com/$echo$username/${map[$i]}.git
git push -u $i $echo$branch
done
git push;;
4) echo "Quitting..."
exit
;;
*) echo "Invalid operation"
;;
esac
done