Skip to content

Commit 677bd2e

Browse files
added git automation script
1 parent 2fb5cdd commit 677bd2e

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

github.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#! /bin/bash
2+
3+
### Git automation script for automating git clone, push and pull ###
4+
### Created by PIYUSH-MISHRA-00 ###
5+
6+
while :
7+
do
8+
echo
9+
echo "Which Git operation you want to perform ?"
10+
echo
11+
echo "GitHub username: $username"
12+
echo "Local repository name: $local_repo"
13+
echo "Remote repository name: $remote"
14+
echo "The default branch you want to work with: $branch"
15+
echo "GPG key value: $GPG"
16+
echo
17+
echo -e "\t(0) Configure (configures the script for continuous uses)"
18+
echo -e "\t(1) Clone"
19+
echo -e "\t(2) Pull"
20+
echo -e "\t(3) Push"
21+
echo -e "\t(4) Exit"
22+
echo -n "Enter your choice [0-4]: "
23+
24+
read choice
25+
26+
case $choice in
27+
28+
0) echo "Enter the values for future use of the script..."
29+
echo
30+
echo "Enter GitHub username: "
31+
read username
32+
export username
33+
echo "Your username is: $username"
34+
echo
35+
echo "Local repository name: "
36+
read local_repo
37+
export local_repo
38+
echo "Your local repository name is: $local_repo"
39+
echo
40+
echo "Remote repository name: "
41+
read remote
42+
export remote
43+
echo "Remote repository name is: $remote"
44+
echo
45+
echo "The default branch you want to work with: "
46+
read branch
47+
export branch
48+
echo "The default branch you want to work with: $branch"
49+
echo
50+
echo "GPG key value is: $GPG"
51+
echo
52+
echo "GPG key id for signed commits(leave blank if you don't want signed commits)"
53+
read GPG
54+
export GPG
55+
echo "GPG key value is: $GPG"
56+
echo
57+
;;
58+
59+
1) echo "Cloning from GitHub"
60+
echo
61+
echo "Enter the repository https url: "
62+
read clone_url
63+
git clone $echo $clone_url;;
64+
65+
2) echo "Pulling from GitHub"
66+
echo
67+
echo "Enter the repository https url: "
68+
read pull_url
69+
echo
70+
echo $pull_url
71+
echo
72+
while :
73+
do
74+
echo "Which type of Git Pull you want ?"
75+
echo -e "\t(1) Merge (the default strategy)"
76+
echo -e "\t(2) Rebase"
77+
echo -e "\t(3) Fast-forward only"
78+
echo -e "\t(4) Return to main menu"
79+
echo -n "Enter your choice [1-4]: "
80+
read pull_choice
81+
case $pull_choice in
82+
1)
83+
git config pull.rebase false
84+
git pull $echo "$pull_url";;
85+
2)
86+
git config pull.rebase true
87+
git pull $echo "$pull_url";;
88+
3)
89+
git config pull.ff only
90+
git pull $echo "$pull_url";;
91+
4)
92+
break
93+
;;
94+
*)
95+
echo "Invalid operation"
96+
;;
97+
esac
98+
done
99+
;;
100+
101+
3) echo "Pushing to GitHub"
102+
declare -A map
103+
104+
map[$echo"$local_repo"] = $echo"$remote"
105+
106+
git config --global user.name $echo"$username"
107+
git config --global user.signingkey $echo$GPG
108+
git init
109+
git add .
110+
echo "Enter Commit message: "
111+
read message
112+
git commit -m $echo "$message"
113+
echo "Enter Tag name: (Press enter if you want to skip the tag name)"
114+
read tag
115+
echo "Enter Tag message: (Press enter if you want to skip the tag message)"
116+
read tag_message
117+
git tag -a $echo$tag -m "$echo$tag_message"
118+
git tag -n
119+
120+
for i in "${!map[@]}"
121+
do
122+
git remote add $i https://github.com/$echo$username/${map[$i]}.git
123+
git push -u $i $echo$branch
124+
done
125+
126+
git push;;
127+
128+
4) echo "Quitting..."
129+
exit
130+
;;
131+
132+
*) echo "Invalid operation"
133+
;;
134+
135+
esac
136+
done

0 commit comments

Comments
 (0)