-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
308 lines (259 loc) · 12.4 KB
/
install.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#! /bin/bash
# clone: ovverride the standard clone with clone recursive
git config --global alias.clone "clone --recursive"
# commit: includes the commit signature by default in the commit message: Signed-off-by: alessandroargentieri <[email protected]>
git config --global alias.commit "commit -s"
# lasttag, returns the last tag according to the semantic versioning
# usage:
# $ git lasttag
# v1.4.6
git config --global alias.lasttag '!f() { git fetch -tp &>/dev/null; git tag -l "v*" --sort=v:refname | tail -1; }; f'
# lasttag-env, returns the last tag for the specified environment (qa, dev, prod, test)
# usage:
# $ git lasttag-env qa
# qa-v1.3.4
git config --global alias.lasttag-env '!f() { git tag -l "${1}-v*" --sort=v:refname | tail -1; }; f'
# tags, list of local or remote tags
# usage:
# $ git tags
# $ git tags -r
# $ git tags --remote
git config --global alias.tags '!f() { git fetch -t; if [ "$1" == "-r" ] || [ "$1" == "--remote" ]; then git ls-remote --tags origin; else git tag; fi; }; f'
# ls, better logging, showing the history tree with less bash command
# usage:
# $ git ls
# $ git ls develop
git config --global alias.ls '!f() { git log $1 --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%ae,%ar]" --decorate --graph; }; f'
# bl, improved blame
# usage:
# $ git bl origin/develop -- path/to/the/file
git config --global alias.bl 'blame -c --date=short'
# check most recent commit to have modified a specific file
# usage
# $ git last-change path/to/file
git config --global alias.last-change '!f() { git log -n 1 --pretty=format:"%h - %an, %ar : %s" -- $1; }; f'
# ch, checkout
# usage:
# $ git ch master
# git config --global alias.ch 'checkout'
# typo aliases to manage errors while typing
git config --global alias.st 'status'
git config --global alias.statsu 'status'
git config --global alias.stats 'status'
git config --global alias.tstatus 'status'
git config --global alias.statys 'status'
git config --global alias.statyus 'status'
git config --global alias.statsy 'status'
git config --global alias.stayus 'status'
git config --global alias.sttaus 'status'
git config --global alias.sttats 'status'
git config --global alias.statuys 'status'
git config --global alias.psuh 'push'
git config --global alias.psush 'psush'
git config --global alias.brancg 'branch'
# m, merge
# usage:
# $ git m feature/DASH-123
git config --global alias.m 'merge'
# b, br, branch
# usage:
# $ git br -D branch-to-delete
git config --global alias.b 'branch'
git config --global alias.br 'branch'
# com, commit
# usage:
# $ git com -m "message"
git config --global alias.com 'commit'
# a, add
# usage:
# $ git a .
git config --global alias.a 'add'
# t, tag
# usage:
# $ git t v1.2.3
git config --global alias.t 'tag'
# f, fetch
# usage:
# $ git f -tpf
git config --global alias.f 'fetch -tp'
# unstage, restore all staged files
# usage:
# $ git unstage
git config --global alias.unstage 'restore --staged .'
# reverte-merge, reverts a merge returning on the principal branch
# usage:
# $ git revert-merge
git config --global alias.revert-merge 'revert -m 1'. # git revert-merge <merge-commit-hash>
# x, compare branches
# usage:
# $ git x br1..br2
# $ git x br1...br2
git config --global alias.x 'log --oneline' # git x branch1..branch2
# addmod, add to stage only modified files
# usage:
# $ git addmod
git config --global alias.addmod '!f() { git ls-files --modified | xargs git add; }; f'
# common, checks what is the last common commit between the two specified
# usage:
# $ git common branch1 branch2
git config --global alias.common 'merge-base'
# switch, checkout or creation of a new branch
# usage:
# $ git switch new-or-existing-branch
git config --global alias.switch '!f() { git checkout $1 2>/dev/null || git checkout -b $1; }; f'
# wip, save a working in progress by stashing tracked and untracked files
# usage:
# $ git wip 'DASH-123'
git config --global alias.wip '!f() { git stash save $1 -u ; }; f'
# wip-apply, apply a stash by its message
# usage:
# $ git wip-apply 'DASH-123'
git config --global alias.wip-apply '!f() { temp=$(git stash list | cut -d ':' -f 3 | grep -n -w $1 | cut -d ':' -f 1) ; stashnum=$((temp-1)) ; stashname=$(echo stash@{$stashnum}) ; git stash apply $stashname ; }; f' # git wip-apply 'embeddedTomcat'
# commits-behind, see which commits your current local branch is behind the specified remote one (remote or local)
# usage:
# $ git commits-behind master
# $ git commits-behind origin/develop
git config --global alias.commits-behind '!f() { git fetch -tpf > /dev/null 2>&1; git log --oneline $(git branch --show-current)..$1; }; f'
# commits-diff, see the which are the commits the current branch and the specified branch (local or remote) differ
# usage:
# $ git commits-diff master
# $ git commits-diff origin/master
git config --global alias.commits-diff '!f() { git fetch -tpf > /dev/null 2>&1; git log --oneline $(git branch --show-current)...$1; }; f'
# checkabout, checkout on a branch for which you only partially remember the name
# usage:
# $ git checkabout oauth2
# Switched to branch feature/DASH-123_implementing-oauth2-rest-services
# N.B. if more branches are found, it optimistically checkout on the first one
git config --global alias.checkabout '!f() { git checkout `git branch | grep $1 | head -1 | cut -d "*" -f 2`;}; f'
# checkouts, lists the previous checkouts on the current repository
# usage:
# $ git checkouts
git config --global alias.checkouts '!f() { i=0; count=0; while [ $? -eq 0 ] && [ $count -lt 10 ]; do i=$((i+1)); branch=$(git rev-parse --symbolic-full-name @{-$i} 2> /dev/null); [ -z "$branch" ] && break; count=$((count+1)); echo "$count. $branch"; done; }; f'
# ch, improved version of checkout
# usage:
# $ git ch --
# it's like $ git checkout @{-2}
# $ git ch ---
git config --global alias.ch '!f() { if [[ $1 == "--" ]]; then git checkout @{-2}; elif [[ $1 == "---" ]]; then git checkout @{-3}; else git checkout "$@"; fi; }; f'
# branch-name, returns the name of the current branch
# usage:
# $ git branch-name
git config --global alias.branch-name 'branch --show-current'
git config --global alias.current 'branch --show-current'
git config --global alias.get-current 'branch --show-current'
git config --global alias.current-branch 'branch --show-current'
git config --global alias.branch-current 'branch --show-current'
git config --global alias.get-branch 'branch --show-current'
# pushnew, push a new branch setting the upstream (equivalent to: git push -u origin `git branch --show-current`)
# usage:
# $ git pushnew
git config --global alias.pushnew '!f() { git push -u origin `git branch --show-current`; }; f'
# tag-date, returns the date of a tag
# usage:
# $ git tag-date v1.2.3
git config --global alias.tag-date '!f() { git log --tags --simplify-by-decoration --pretty="format:%ci %d" | grep $1; }; f'
# behind, returns what commits the remote branch is ahead of your current local one
# usage:
# $ git behind
git config --global alias.behind '!f() { git fetch -tpf &>/dev/null; export BRANCH_NAME=$(git branch --show-current); git log --oneline $BRANCH_NAME..origin/${BRANCH_NAME}; }; f'
# commit-diff, returns which files have been modified between two commits
# usage:
# $ git commit-diff <sha1> <sha2>
git config --global alias.commit-diff 'diff --name-status'
# reset-hard, does a reset --hard and removed untracked files and folders
# usage:
# $ git reset-hard
git config --global alias.reset-hard '!f() { git reset --hard; git clean -df ; }; f'
# whoami, returns username and email registered with git
# usage:
# $ git whoami
git config --global alias.whoami '!f() { echo "`git config user.name` `git config user.email`"; }; f'
# get-url, returns the url of the associated remote (it supposes it's named 'origin')
# usage:
# $ git get-url
git config --global alias.get-url 'config --get remote.origin.url'
# set-url, sets the remote url (it supposes it's named 'origin')
# usage:
# $ git set-url https://<username>:<token>@github.com/<accountname>/<reponame>
git config --global alias.set-url '!f() { git remote set-url origin $1 ; }; f'
# set-remote-url, sets the remote url
# usage:
# $ git set-remote-url <remote-name> https://<username>:<token>@github.com/<accountname>/<reponame>
git config --global alias.set-remote-url '!f() { git remote set-url $1 $2 ; }; f'
# get-remote-url, returns the url of the associated remote
# usage:
# $ git get-remote-url <remote-name>
git config --global alias.get-remote-url '!f() { git config --get remote.$1.url; }; f'
# set-token add the Github token to the origin remote url
# usage:
# $ git set-token
# So when you do `git get-url` before launching this command you get: https://github.com/myorg/myrepo.git
# After having launched the command you'l' get https://<YOUR-GITHUB-TOKEN-HERE>@github.com/myorg/myrepo.git
# Substitute the <YOUR-GITHUB-TOKEN-HERE> with your real Github token
git config --global alias.set-token '!f() {
url=`git config --get remote.origin.url`
prefix=https://github.com
newprefix=https://<YOUR-GITHUB-TOKEN-HERE>@github.com
newurl=${url/$prefix/$newprefix}
git remote set-url origin $newurl
}; f'
# remote2remote, push a remote branch into another one (which exists or not), without cloning locally
# usage:
# $ git remote2remote my_remote_branch new_branch
git config --global alias.remote2remote '!f() { git fetch -tpf &>/dev/null; git checkout origin/$1 &>/dev/null; git push -f origin HEAD:refs/heads/$2; git checkout - > /dev/null; }; f'
# reset-author, resets last commit's author
# usage:
# $ git reset-author <name> <email>
git config --global alias.reset-author '!f() { git config user.email ${2}; git config user.name "${1}"; git commit --amend --reset-author; }; f'
# aliases, returns the list of all git aliases
# usage:
# $ git aliases
git config --global alias.aliases '!f() { git config --get-regexp "^alias\." | cut -d " " -f 1 | cut -d "." -f 2 ; }; f'
# get-alias, returns the details of a specific alias
# usage:
# $ git get-alias <alias-name>
git config --global alias.get-alias '!f() { git config --get-regexp "^alias\." | grep $1 ; }; f'
# release, allows doing a release through a tag
# to get the usage:
# $ git release --usage
git config --global alias.release '!f() {
RESET=`tput sgr0`
GREEN=`tput setaf 2`
CYAN=`tput setaf 6`
YELLOW=`tput setaf 3`
BOLD=`tput bold`
LASTTAG=$(git lasttag | cut -d 'v' -f 2)
SPLITTED=(${LASTTAG//./ })
for i in {0..2}
do
SPLITTED[$i]=`echo ${SPLITTED[$i]} | cut -d '-' -f 1`
[ "${SPLITTED[$i]}" != "" ] || SPLITTED[$i]=0
done
INDEX=2
if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ "$1" == "--usage" ]; then
echo ""
echo "Creates a ${BOLD}${YELLOW}new tag${RESET} from the current commit."
echo "Usage: "
echo " git release ${GREEN}[--patch] [--snapshot] ${CYAN}# creates a new patch release ${RESET}"
echo " git release --minor ${GREEN}[--snapshot] ${CYAN}# creates a new minor release ${RESET}"
echo " git release --major ${GREEN}[--snapshot] ${CYAN}# creates a new major release ${RESET}"
exit 0
elif [[ "$1" == "--major" ]]; then
SPLITTED[0]=$((SPLITTED[0]+1))
SPLITTED[1]=0
SPLITTED[2]=0
INDEX=0
elif [[ "$1" == "--minor" ]]; then
SPLITTED[1]=$((SPLITTED[1]+1))
SPLITTED[2]=0
INDEX=1
else
SPLITTED[2]=$((SPLITTED[2]+1))
fi
if [ "$1" == "--snapshot" ] || [ "$2" == "--snapshot" ]; then
SPLITTED[$INDEX]=${SPLITTED[$INDEX]}-SNAPSHOT
fi
echo "Latest tag found: ${BOLD}${YELLOW} `git lasttag`${RESET}"
git tag v${SPLITTED[0]}.${SPLITTED[1]}.${SPLITTED[2]}
echo "New release tag: ${BOLD}${GREEN} `git lasttag`${RESET}"
}; f'